Yii Framework Forum: Where to Start with Yii - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Where to Start with Yii Rate Topic: -----

#1 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 03 June 2009 - 02:34 PM

[UPDATE Oct 11/09]
In a new comprehensive guide I'm working on, I remodelled this tutorial to fix any bugs, make it work without the need for a database and provided screen shots. Here is the link, it's in PDF format.

http://www.sterlingsavvy.com/Update - Where to Start with Yii.pdf

[UPDATE]


Hi folks. I'm new to Yii, I'm new to frameworks so in the process of trying to find out myself where to start I designed this tutorial. For most of the users who submit to these parts of the forums this will be completely useless to you except to critique. However this is meant to be geared at complete new users to Yii, even new to PHP Frameworks. Maybe if it's good enough it'll be something they start using to introduce users to Yii.

I would love for people to have a read and rate it on it's simplicity, clarity and anything else you want to comment on. I will warn you it is roughly 5000 words (approx 10 typed pages) in length so it is timely to go through. However even if you just skim through the parts that are important to the "coding" as opposed to the defining MVC and OOP, it may be shorter.

There is also a lot of "dialogue" if you wish about my own personal views and exp​ressions that I find help personalize the tutorial and make it more user friendly giving the reader a better sense of what they are doing.

I can make revisions as needed for typos, clarity or generally just adding / removing parts of it. It's written in Canadian English. Enjoy :)

http://www.sterlings...0with%20Yii.pdf

Kyle

[EDIT] The new link to the html version can be seen below (for those too lazy to read through all the posts

www.sterlingsavvy.com/tutorials/index.php

[New Edit] Apparently the new forums altered the links, heres' the address.

www.sterlingsavvy.com/tutorials/index.php

Also would like to add a little note: just established that in order for this to work, a db connection has to be setup. To bypass that issue, just create your own model class (since that's the problem because of CActiveRecord). I will be making a new updated version soon in a total Yii guide.

Also note that it's \ not / to paths in Yiic

Sorry for any confusion!

0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,892
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 June 2009 - 07:02 PM

Nice writing! You should probably make an online HTML version of it.

Here are my comments:
1. The model and crud commands in yiic shell will not work without a DB connection (the model command actually works in 1.0.5, but crud requires 'db'). In the upcoming 1.0.6, both would require a 'db' connection. Since you are showing working with a form model, maybe you may manually create the needed files. That would also cause less confusion to beginners.

2. In actionIndex(), why would you check isset($message->message)? Since $message is new, this check would always fail unless you set some default message value.

3. In the index.php view file, the links can be created using syntax like the following, which avoids embedding direct URLs in your code:

<?php echo CHtml::link('Here', array('message/show')); ?>

0

#3 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 03 June 2009 - 10:54 PM

Thanks for the comments. Yeah I can look to make it a more user friendly HTML version and even break it up into sections of the process. I'll work on something and post a link to it.

As for the yiic commands, yes I realize building a model implies you're using a db (hence the extends CActiveRecords of the class) and a table name is usually the model name. However because I didn't know what I was doing with Yii, I was writing the tutorial as I went along and used that as my building bases for the controller. Now I understand that the models go under the model directory and the associated views are made within a folder called YourID for the views. Stuff that if you start from scratch just building your own files you'd have to already know the architecture really well.

I think having the pre-built templates help to new users just to play with things and see what they do. It's easier for beginners to work with a class already built then to have to start one from scratch, it takes a great understanding of both the framework and OOP to do that. In my second tutorial I was going to work with that, creating the classes from scratch - teaching users how to read from the Yii class reference documentation to find the methods that help them complete what they want to do.

As for actionIndex(), I'll be completely honest I was thinking of originally making it save variable information so that way the edited message gets displayed when you view the show action. However I soon realized that A) I'm not working with a db, so it's not stored there anywhere. And B) I'm not working with sessions (haven't looked into it so I'm not to sure how they work with the framework).

Thus isset($message->message) is pretty useless except it did it's toll for the editing action, because the edit action forwards to the show action when you edit the string. When that happens, that isset() actually returns true and it renders the newly editing message, it just doesn't keep it. I didn't bother being picky about it because it was just something simple that was only emphasizing how to use models with controllers and views.

If there's a better way to evaluate the process I'm inclined to hear it, after all it's a learning process for me too :).

Finally thanks for pointing out that about the CHtml::link, I'll change them to that format. I don't know why I didn't catch it myself, I mean I used it in the main menu lol. I'll actually make a reference to it as well in the tutorial because a link is probably one of the more widely used html actions beginners will try to use.

Thanks again for the comments, I'll post a message when everything is updated.
0

#4 User is offline   wei 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 147
  • Joined: 04-October 08

Posted 04 June 2009 - 08:54 PM

Also, I think some screenshots of the progress would also help the reader to see where they are heading.

Nice work!
0

#5 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 10 June 2009 - 12:00 AM

Ok sorry for the delay, I've been a little busy.

So I built a template setup from scratch, nothing fancy, for the html version. I must say that the html <code> and <pre> tags are a pain in the ass to use, but the fact that I did everything in php using echo statements probably didn't help.

I haven't gotten around to doing screen shots yet however I do like the idea and will do some, it's just because the project is already completed on my part I have to do it again and take screens as I go (instead of modifying all the required code).

This will give me a chance to follow my own tutorial and see how it reads and what to do. I'll probably add in a thing or two that isn't clear (like the public variables for the model).

Anyway here's the link: http://www.sterlings...rials/index.php , all comments are welcomed. I also updated all the links to the proper Yii CHtml use (much easier and nicer I might add lol) and I made some note references about the isset action for the show page and why it won't log the variables (thus always fail) unless coming from the edit page.

As for the idea of manually creating the model / controllers due to using form instead of AR, I think I'll leave it as that because it lets the users play around with it and also if they want to go above and beyond and use a db to hold the string message information, they can. More importantly it's simplier than trying to build a class from scratch which I will be doing for the 2nd tutorial which I will do and post there. I have a feeling I'll be doing quite a few tutorials on here, maybe 1 a day if I can muster it (maybe not design wise but write ups for sure) because I'm still learning Yii myself, but I'm so impatient! I just want to build my site lol.

[EDIT]

Figured I'd just mention that after a little more review of the tutorial from feedback and my own views, I'll proceed to place it in the cookbook. I just want to make sure it's as clear and easy to follow as possible before I do that.
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,892
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 June 2009 - 06:40 AM

Your page layout has problem because the main section goes below the TOC. Other than this, it looks good to me. Putting it in cookbook is a good idea. You may separate it into many cookbook pages and have a TOC page to link them together.
0

#7 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 10 June 2009 - 10:28 AM

Gah, did I ever mention how much I hate css coding for cross-browser capability lol. IE doesn't put a vertical slider for some reason, but you can select the text and and drag down? That's just messed. I'll get on that when I get the chance. thanks for pointing it out, often when I do small things I just check good old FF to see how things work but for get to check other browsers.
0

#8 User is offline   drech 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 06-April 09

Posted 07 August 2009 - 11:55 PM

What's the proper URL for this? http://www.sterlings...rials/index.php

Thanks!
0

#9 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 07 August 2009 - 11:59 PM

Good question... hah wonder why it removed it anyway: In case it does it again that's the address sterlingsavvy.com/tutorials/index.php

And this should be a working url: http://www.sterlings...rials/index.php

I haven't done anything with this in a while. As soon as I finish up my Ajax readings and ActionScript I'll be back to Yii and I'll be making a full guide from the ground up with a decent site setup and set it through in the cook book section. Eitherway, this should introduce you to how Yii works with models, views and controllers and give you a little bit on OOP and MVC framework design.
0

#10 User is offline   abc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-August 09

Posted 27 August 2009 - 03:23 AM

why I dont understand you say?
I dont know how to load and dont know to start the yii.
I'm studying in Thaiload. This year I am doing a project finished.

I hope someone will advise me.

thak
0

#11 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 27 August 2009 - 06:35 AM

View Postabc, on 27 August 2009 - 03:23 AM, said:

why I dont understand you say?
I dont know how to load and dont know to start the yii.
I'm studying in Thaiload. This year I am doing a project finished.

I hope someone will advise me.

thak


Send me a pm of what you know and don't know and where you're at and I'll see about getting you started 1 on 1. This tutorial is a little jumbled (my fault) as it's using some methods that may not work if you do not have an active database connection.
0

#12 User is offline   rohitpant 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 20-September 09

Posted 08 October 2009 - 03:15 AM

Where can i get the PDF version of the tutorial ? I run a startup and want my folks to understand YII in detail. This might help. Please pass on the URL to download the PDF

my email id is rohitpant@gmail.com

thanks in advance and looking fwd to your email

regards,
rohit
0

#13 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 08 October 2009 - 05:41 PM

View Postrohitpant, on 08 October 2009 - 03:15 AM, said:

Where can i get the PDF version of the tutorial ? I run a startup and want my folks to understand YII in detail. This might help. Please pass on the URL to download the PDF

my email id is rohitpant@gmail.com

thanks in advance and looking fwd to your email

regards,
rohit


I'm heading out on a business trip for 2 days. I will be back Saturday (it is currently Thursday for me) and I will contact you with that information on Saturday. Sorry for the delay.
0

#14 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 11 October 2009 - 12:42 PM

Update to all, there's a new, revised version of this tutorial and you can get the pdf via the link in the first post - it's at the top in the [UPDATE] notice.

Also, email sent to you rohitpant.
0

#15 User is offline   Yada 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 28-October 09

Posted 30 October 2009 - 11:22 AM

Very nice tutorial.

I followed it and managed to get the Hello World program running.

Just some suggestions:
- put filename to label each code section. Some time I see a piece of code and I'm not sure where to find the file. eg ./protected/models/MessageForm.php

- Show a code file in whole.

Would like to read more chapters if you have any.

I'm slowly learning the Yii Framework. Have decided with Yii over the others.
0

#16 User is offline   Lucky Murari 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 20-November 09

Posted 21 November 2009 - 02:23 AM

@whoopass Small glitch in the PDF tutorial. The rules funtion is expected to be
public function rules() {
    return array(
    // author and message are required
array('author,message','required'),
);
}


The change in the function is
array('author,message','required')
should be used instead of
array('author','message','required')

0

#17 User is offline   beginners 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 11-December 09

Posted 11 December 2009 - 03:56 PM

hello can u help me.. when i created new web app @ my computer i receive a error message like this :



C:\Program Files\xampp\htdocs>.\frameworks\yii\framework\yiic webapp test
'php.exe' is not recognized as an internal or external command,
operable program or batch file.

C:\Program Files\xampp\htdocs>

what should i do.. sory im beginner!! thx!
0

#18 User is offline   whoopass 

  • Advanced Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 27-May 09
  • Location:Ajax, Ontario, Canada

Posted 11 December 2009 - 04:12 PM

View Postbeginners, on 11 December 2009 - 03:56 PM, said:

hello can u help me.. when i created new web app @ my computer i receive a error message like this :



C:\Program Files\xampp\htdocs>.\frameworks\yii\framework\yiic webapp test
'php.exe' is not recognized as an internal or external command,
operable program or batch file.

C:\Program Files\xampp\htdocs>

what should i do.. sory im beginner!! thx!


Sounds like you don't have php installed. Do you know if you have it installed? Would be a php or php5 in program files.
0

#19 User is offline   beginners 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 11-December 09

Posted 11 December 2009 - 05:31 PM

i think i have @ my xampp bundle...
can u help me??
0

#20 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 11 December 2009 - 06:40 PM

View Postbeginners, on 11 December 2009 - 05:31 PM, said:

i think i have @ my xampp bundle...
can u help me??


Check if this cookbook article can help you out.

I'm not familiar with XAMPP, but if you successfully ran the requirements check you probably need to add a PHP path to the command line environment.

/Tommy

This post has been edited by tri: 11 December 2009 - 06:50 PM

Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users