Professional Documents
Culture Documents
http://www.yiiframework.com/wiki/250
github twitter facebook guide class reference guide 2.0 api 2.0 wiki extensions forum live chat login
DOCUMENTATION
Tutorials
Class Reference
Guide 2.0
Follow @yiiframework
80 followers
Wiki
Screencasts
Resources
13.1K followers
97
report it
Intro (Part 1)
S E AR C H W IK I
1. Prerequisities
2. MVC - Architecture description
2.1. Controller
2.1.1. Action
2.2. Model
2.3. View
3. What is it framework and why to use it
4. Yii framework
4.1. The demo project and folder structure
5. Using Yii in praxis
5.1. Create demo project and set it up
5.2. Create Database for your project
5.2.1. DB design tool
5.2.2. Run Yiic shell or Gii
5.2.3. Define relations in models manually
5.3. How to create your first controller
Related Articles
Yii HMVC
Intro (Part 1)
Hi. This is first article with my Yii tutorial. I had to split it into more articles as there's limited length of texts on
Wiki. So once you understand basics, you can read next article here: Yii for beginners 2.
This tutorial is copy of PDF in my forum: Total fresher in PHP frameworks and Yii, I don't understand tutorials
I'm writing this tutorial because when I was beginning with Yii I was totally lost. I didn't understand anything. I
didn't know why I needed the demo project, where I should place my PHP scripts, what it means MVC, what
should the folder structure look like etc. No tutorial for beginners was available.
This tutorial is meant for beginners who have never worked with any PHP framework or with Yii. Who are able to
create website with standard PHP, MySQL etc., but are completely lost while beginning with Yii.
1. Prerequisities
I suppose the reader is familiar with PHP and databases (DB). He should be able to write SQL query, use DB in
PHP and create at least a simple web using PHP, HTML, CSS and DB. If you dont know anything about PHP
and DB, I recommend that you stop reading and have a look at it. And whats also important is OOP (Object
1 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
oriented programming). This means classes, overriding functions, using constructor, public and private methods
and properties, etc Can be practiced in PHP, Java, C#, VB.NET
2.1. Controller
Controller is initiated (and it's code is run) whenever you enter any address in browser. In its code you can read
data from POST, GET or SESSION variables, work with DB etc. When you use MVC architecture (in Yii
framework), addresses have special format. They include parameter that specifies which controller will be used.
(which part of web you want to enter)
Yes, you can have more controllers. Each controller can be used to work in different part of your web. One
controller can work with user accounts, another one with products you sell etc. And what does the web address
look like when you use MVC?
www.myweb.com/index.php?r=myController
Parameter r says that you want to use Controller named myController. And here we can see another
speciality of MVC (or Yii). Addresses contain only index.php. No other files. All the navigation is done by the r
parameter and controllers.
2.1.1. Action
Controller can have one or more sub-controllers. Each does something else. If our controller works with users
than his one sub-controller can delete users, another one can add users, third one changes (edits) them
These sub-controllers are called Actions. You can (have to) specify action using the r parameter. As we saw
above, controller was specified like this: ?r=myController. If our controller had action called myAction, and if
we wanted to run it, we would write this address:
www.myweb.com/index.php?r=myController/myAction
www.myweb.com/index.php?r=users/edit
2 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
If you do not specify action and run only controller like this ?r=myController than the default action will be run.
The default action has to be specified in the controller using function actionIndex().
2.2. Model
Model is very simple thing in Yii. You dont have to write a single line of its code, it can be created automatically
using command line. Each table in DB has its own model. This model has the same (or similar) name like the
table. Each model has 2 important functions. Find data and Save data. Thats all we usually need. When you
need to read data from DB to controller you just write something like:
ModelName.FindAll()
and thats it. No SQL queries, no fetching array (as you would have to do in PHP). Thats the advantage of Yii
and its object-oriented access to DB. When you want to write to table, the command looks cca like this:
ModelName.column=value;
ModelName.Save()
Thats it again.
Another thing that the Model provides is relations. These relations enable you to tunnel through one table to
another. Important are Foreign Keys. Relation is something like SQL Join. When every employee has in its table
the ID of his department, you can easily get info about this department by writing something like this:
$employee>department>departmentName
Where $employee is 1 particular employee selected by some criteria, the word department is name of the
relation (leading from model of employees to model of departments) and departmentName is column in table of
departments.
2.3. View
As I wrote above, view has no intelligence. It just receives data from Controller and shows them. This is the only
place where we use HTML, CSS, JavaScript etc. We of course can use FORs, WHILEs, Ifs, models But the
only aim is to show data to user.
Correction: Described View is an ideal view. In praxis its sometimes easier for beginners not to send data from
Controller to it, but to read data from DB in View (using model) and show then.
echo CHtml::beginForm();
<form method=postaction=thisScriptName>
And why to use frameworks? It makes your work easier. You dont have to code every single detail, framework
does something for you automatically. Yii for example integrates form-validation functions, it handles user logging
and much more. You just have to discover its possibilities and learn to work with them. But its the hardest thing.
(Sometimes its faster to create your own function than to try to understand a prepared solution) And thats why I
write this manual. To show some possibilities in one place and in praxis so you wont have to google the basics.
4. Yii framework
Yii framework has its web and documentation. All you need to do (if you want to use it) is to download and
extract it to your localhost-folder. You of course need a PHP and MySQL server (I use WAMP. If you want to try it,
turn off Skype for the moment when Wamp is starting. Otherwise it wont start.)
3 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
Instead of command line you can use GII webpage in your demo project. I write about it bellow, but I do not use
4 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
it.
5 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
When youre done with DB design, you just have to press Ctrl+G and DB will be exported to your MySQL server.
I recommend that you go to menu Tools / Options and set History size to ca 10-30 steps. Default value is 0,
which means unlimited number of undo steps. But it slows down the application very very much.
In versions released in year 2011 I noticed their instability under Win XP SP3. So be patient it crashes very often.
But luckily, work is not lost.
6 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
used it but you can. Gii is webpage that comes with Yii framework. In protected/config/main.php you have to
uncomment it and enter password for Gii. Than go to you localhost website and run controller gii like this:
localhost/myproject/index.php?r=gii
$Employee=Employees::model()>findByPk($employeeId);
$myJobName=$Employee>job>jobName;
/*
Where:
Employees=modeloftablecreatedusingyiicshell.
jobName=columninJobstable.
job=relationname.
$Employee=1returnedrecordfromtableEmployeesonlyonebecauseweweresearchingby
PK.IfwesearchedusingfindAll()itwouldreturnlistofrecordsanditwouldbe
necessarytowalkthroughthemusingforeach.
Inyourmodelshouldbeccathisfunction:
*/
<?php
class MyfirstController extends Controller
{
public function actionIndex()
{
//hereisyourcodeforthisaction
}
7 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
}
?>
As you can see, controller is a Class and contains definitions of action and non-action functions. Default and
important action is actionIndex(); Its used when you dont specify any action in r parameter (as mentioned
above). You can add any action you want. For example My action. The r parameter of actionMyaction would
look like this:
?r=Myfirst/Myaction.
$this>render(myview);
It tells the action to run a view. View is the part of your application, where you use HTML, CSS formatting etc.
and its used to show anything to user. (You can also try function renderPartial() can be usefull)
Yii will look for this view in folder Views/Myfirst. Where Myfirst is name of controller. Yes, every controller has its
own set (folder) of views.
In Yii the view is actually a part of Controller. You can call it in any action and when you write "$this" in view, you
are refering to current Controller, its methods and properties. So if there is something that will be common for all
views, you can add it to file "protected/components/Controller.php" because all controllers are based on this
class.
Yii::app()>session[varName]=$value;
Thats it. Session variable will be automatically registered, session will be started, etc.
$employees=$department>get_employees;//(get_employees=relationname)
You can also specify which employees you want to get - by DB column name:
$employees=$department>get_employees(array('condition'=>'born<1950'))
$subMenuItems=
MainMenu::model()>with('relation1.relation2')>findAll(array('condition'=>'id>21and
relation2.tableColumnName=3','order'=>'relation1.tableColumnName'));
Explanation: Model named MainMenu has relation named relation1 which is pointing to another model (to
another table in DB). The target model has relation named relation2 referring to a third table. Using following
command we join 3 tables:
MainMenu::model()>with('relation1.relation2')
8 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
If you want to use your project name in this title or anywhere else, you can use this system variable:
Yii::app()>name
5.4. View
View is a very simple thing so I will just show some "tricks". Html code can be generated semi-automatically
using static class CHtml.
</select>
echo CHtml::dropDownList($name,$select,$data,$htmlOptions);
$htmlOptions=array('width'=>'100','style'='color:red;')
$data is basically a simple array with name=>value pairs. This Array can be created automatically using
function:
$data=CHtml::listData( Model::model()>findAll(),'id_item','item_descr' )
array(value1=>caption1,value2=>caption2)
$models = list of items. Its clear, you use for example: MyModel::model()->findAll(array(condition=>id>4))
$valueField = what column will be used to fill the value of tag
9 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
//firstwecreatethejoinandin$recordyouhavecompletetableofcountriesandtheir
continents.
$records=Country::model()>with('getContinent')>findAll();
$data=
CHtml::listData($records,'id_country','country_name','getContinent.continent_name');
echo CHtml::dropDownList('myDropDown','',$data);
Note that to specify the "group column" you have to use the relation name to tell YII which column from the joined
tables you want. In joined tables are used aliases.
getContinent.continent_name
If you were refering to the "home model" table, you would write only "t.columnName" - in our case to get data
from Country table.
echo CHtml::link("text",array('controller/action'));
//or
echo CHtml::link("text",$this>createUrl('controller/action'));
//andwheneveryouwanttocreateURLleadingtoapageonyoursite,use:
$this>createUrl('controller/action');
Because URLs can have more formats in Yii and if you change the format (in protected/config/main.php) and use
this method, links will be automatically changed too. If you enter them manually, they will stop working.
If you do not specify controller, the current controller will be automatically used.
$this>render(myview,array(variableName=>$value));
This will show ordinary hyperlink Delete. When its clicked, a JavaScript confirm-box appears. When you click
YES, it does what is written in onclick section. In this case, a form named formName is send to the server.
When you put mouse on the Delete caption, your cursor will be changed to classical hand.
Dont forget to use escape characters when writing javascript using php echo. JS requires apostrophes instead
of quotes. You can't write this:
10 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
<?php echowordinapostrophes;?>
<php echo\'wordinapostrophes\';?>
echo CHtml::form();
//CHtml::textField($name,$value,$htmlOptions)
echo CHtml::textField('myTextField','',
array(
'ajax'=>
array(
'type'=>'POST',//requesttype
'url'=>CController::createUrl('myActionName'),//actiontocall
'update'=>'#updatedDropDownList',//whichHTMLelementtoupdate
)
));
//CHtml::dropDownList($name,$select,$data,$htmlOptions)
echo CHtml::dropDownList('updatedDropDownList','',array(),array());
echo CHtml::endForm();
Whats also important is the word update. It says that referred dropDownList will be extended. In our case we
will add some option values (rows). And here is the code of the underlying action:
//closetag
As you can see, this function only prints some text. In our case its the new option for dropDownList. Because we
told Yii tu update the dropDownList, this printed option will be added to it. Action can of course be more complex.
You can access DB via MyModel::model() and check something.. Its up to you. The only rule is that you have to
echo something. You can echo more records (options) for example using for cycle.
11 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
How to work in the action with data you entered in the first field will be shown bellow.
**echo CHtml::form();**
//CHtml::dropDownList($name,$selected,$values,$htmlOptions)
echo CHtml::dropDownList('country','',array(1=>'hasvalueI',2=>'hasvalueII'),
array(
'ajax'=>
array(
'type'=>'POST',//requesttype
'url'=>CController::createUrl('myActionName'),//actiontocall
'update'=>'#updatedDropDownList',//whichHTMLelementtoupdate
)
));
//CHtml::dropDownList($name,$select,$data,$htmlOptions)
echo CHtml::dropDownList('updatedDropDownList','',array(),array());
**echo CHtml::endForm();**
Tha main difference here is that drop down boxes have to be in a FORM !! Otherwise their vales won't be
accessible via POST in action !!
Below is appropriate action.
echo CHtml::form();
echo CHtml::textField('myTextField','',
array(
'ajax'=>
array(
'type'=>'POST',//requesttype
'url'=>CController::createUrl('myActionName'),//actiontocall
'replace'=>'#statusTextBox,//whichHTMLelementtoupdate
)
));
echoCHtml::textField(statusTextBox,'',array());
echoCHtml::endForm();
In this case is important the **replace ** option. It sais that the original textField named statusTextBox will be
replaced with a new one with different properties (text).
12 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
Notice that the name of the new textbox created in Action must be the same as the name of the deleted textbox.
Otherwise this action will be done only once.
If something doesnt work repeatedly (only once per page refresh), try to generate the HTML FORM ITEM
(textbox, dropdownlist ... ) in Action in a different way.
Read more at: here and here.
Class is saved in file: protected\models\MyModel.php If you want to read data from DB, you use model for
example like this:
$dataFromDb=MyModel::model()>findAll();
//thisreturnsallrowsfromtablethatiscontrolledusingmodelMyModel.
And what means the double-colon :: and arrow ->? Double-colon means that our class MyModel contains static
method model(). If you access static methods and static properties, you use :: and if you access methods of
instance or property of instance, you do it via arrow -> Example:
$myVariable=new MyClass()
$myVariable::myStaticMethod();
$myVariable>myMethodOfInstance();
The static function model() is in the model class and looks like this. (Word parent refers to CActiveRecord class
- your Model is derived from it) You do not need to understand it, just use it.
Another function of your model must be tableName(). It only returns table name that is managed via this model:
Third method is function rules(). It is very important function in case that you want to check data entered into a
13 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
HTML form (for example when editing goods details, filling contact forms etc.) If user enters something wrong he
will be warned and no data will be saved or processed. For example if user should enter his email and forgets @
sign, nothing happens if you specify rules well. Rules are automatically created if you generate model class using
command line. Yii takes these rules from DB definition. That is why you should create DB before programming.
To be more specific rules just say which attribute should be validated using specified validator. If you have a
look bellow, you will see that for example attribute (or column in DB) user_email has to be in form of email.
Attribute age has to be integer = without decimal numbers. So now you know 2 validators: email and numerical.
But there are more of them.
);
}
You can of course create your own validator and use it in a rule. If you want to add rule with name myrule than
in your model-class create function myrule() and to rules enter this: array('my_tested_column', 'myrule'), In
demo project you can find this in praxis in file protected/models/LoginForm.php. Next function is relations(). It
defines connections to other tables. It is created automatically if you specify PK-FK relations. Thats why I
recommend MySQL Workbench for designing DB. See other chapter. Each relation begins with its name than
you have to specify cardinality (relation 1:1, 1:N, M:N), target model, target PK. See text about relations
And finally last default function attributeLabels() defines labels (descriptions) for table columns.
If you change this function so that it doesnt return just array but also takes into consideration desired language,
it can be used to translate captions in forms based on this model. Example:
And the best thing is that if you use console (yiic.bat) to generate models than this class will be created
automatically for each of your tables. The whole MyModel class will look cca like this:
14 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
.. And you can add (override) much more usable functions like scopes(), defaultScope(), afterSave(),
beforeValidate()
$dataFromDb=MyModel::model()>getOnlySomeRows()>findAll();
//thisreturnsallrowsfromtablethatiscontrolledbymodelMyModelandthatcomply
withcriteriaspecifiedbyscopegetOnlySomeRows.
And now my experience from praxis: Lets imagine that you have 2 tables. Table Suppliers and table Users. Each
supplier or user can be signed as enabled or disabled. We want to show all enabled suppliers and their enabled
users. First we will add scopes to Suppliers and Users models like this. In both models the scope will look the
same if there is column status. Lets say that user or supplier is enabled when status is 1.
15 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
Suppliersmodel
);
}
$enabledUsers=Users::model()>getEnabled();
$enabledSuppliers=Suppliers::model()>getEnabled();
But if we wanted to get all enabled suppliers and their enabled users, we would have to use inner join with
conditions. In Yii this can be done by command with() like this:
$ourJoin=
Suppliers::model()>getEnabled()>with(array('getUsers:getEnabled'=>array('joinType'=>'INNE
RJOIN')))>findAll();
I was showing this just because of the colon. If you want to specify relation:scope you use colon. It took me long
hours to find this out so I am mentioning it here. And also notice how to force the inner join.
This default scope adds to each query-result counted column user_complete_name. You than only have to add
this column to your model as a property: public $ user_complete_name'; You could of course use also a JOIN in
the default scope like this: (probably useless example, just to show that it is possible and how to use it)
The important thing to remember is the t that refers to the home table.
2) You can use following command to get current name of table. Usable inside a model class for example in
scopes to specify THIS table. $this->_alias
16 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
//canbeusedinascopelikethis:
'getEnabled'=>array('condition'=>$this>_alias.'.id_status=1'),
3) If you want to see sql query, write something wrong into it. Yii will write the query on the screen:
4) If you use an alias for a column and want to filter records by a condition, do not use where, but having
clause.
That's all. If you are replying to an Ajax call, you just echo something. JavaScript (jQuery) can parse it and can
work with it further. In this case, there is nothing to parse, it's just a simple text.
So the server part is done. Now the client side - JavaScript (jQuery in our case) and HTML.
To include jQuery type to header this: (I recommend to download current version and use it locally)
<script type="text/javascript">
$(document).ready(function(){
$("img.myAjaxImgButton").click(function()
{
//Ifweclickanimagethathasclass"myAjaxImgButton",thiscodewillberun
$.get('url2action',function(data){
//Thiswillbeexecutedwhenajaxcallfinishes
alert(data);
});
//Codewrittenherecanbeexecuted"before"theajaxcall!
//Why?Ajax=AsynchronousJavaScriptandXML=method$.get()iscalled,browser
doesn'twaitforittofinishandprocessesnextrowsofcode.Ifittakes10minutesto
processthe$.get(),nobodywaitsforit.It'sjustrunningondthebackgroundandwhenit
17 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
finishes,internalfunction(data)iscalled.
});
});
</script>
And now evertyhing will be the same as in the previous example. Except for one row in JS code. Instead of
alert(data) we will call the Fancybox like this:
$.get('url2action',function(data){
$.fancybox({content:data});
});
Note that data received from the Action are saved in variable with name "data". But you can use any name you
want of course. For example:
$.get('url2action',function(html){
$.fancybox({content:html});
});
If data contains HTML code, it will be displayed as HTML web page in the modal window. If the data is a Form, it
can contain another Ajax button that will send the form to controller where it will be validated and OK, or list of
errors will be returned.
Note to Fancybox: When we initialized it, we used: {content:html}. "Content" is just one of public properties that
are available in Fancybox. See it's documentation.
In Action, your data will be available via $_GET variable. And if we are using GET method (not POST), our action
can have the same input parameters that are used in $.get() and these will be automatically assigned. Example:
If you want to send the whole form to a controller via Ajax, you have to serialize it. (See method serialize on
jQuery web). But it can't be done by Yii's CHtml::ajaxSubmitButton() if this form is in Fancybox (I don't know
18 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
$(document).ready(function(){
//AsajaxSubmitButtoncanbyusedanythingthathasclass"myAjaxSubmitButton"andis
insideanyform.
//Important!
//Therearemorewayshowtodefinetheclickevent
//1)$(".myAjaxSubmitButton").click(function(){});
//2)$(document.body).on('click','.myAjaxSubmitButton',function(){});
//3)$(".myAjaxSubmitButton").on("click",function(event){});
//4)$('.myAjaxSubmitButton').live('click',function(){});
//Number24shouldworkalways.Method1willworkonlyforobjectsthatwereonour
pagefromthebeginningandweren'tdynamicallyaddedorchangedbyAjaxoraren't
displayedinFancybox.SoifyoudefineabuttonthatwillsendFORMfromFancyboxto
controllerbecauseofvalidation,useoption2or4.Seesection5.6.7.
$(".myAjaxSubmitButton").click(function(){});
{
var serializedForm=$(this).closest('form').serialize();
//Andyoucanaddanyvariableyouwantlikethis:
//varserializedForm=$(this).closest('form').serialize()+'&ajax=1&x=2';
//Serializedwillbeallformelementswithnotemptynameattribute
$.get('url2action',serializedForm,function(data){
alert(data);
});
});
});
In the target action all variables will be available via $_GET array without any unserialization. If we used $.post()
method, they would be in $_POST array. Just try it :)
<tr>..</tr>
... including the edit button. Simply complete row. Once you save the update-form via ajax and close the
Fancybox, HTML code of currently updated row can be also returned and used to replace the original row in list
of users.
19 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
And action:
You can also generate the JS code in action and just evaluate it in browser. You will need JSON object:
//resultvariablecontainsJSON
below
});
And action:
$(document.body).on('change','img.myAjaxImgButton',function() {
alert("Dynamicallyaddedimgbuttonwasclicked!");
});
//Otherpossibilitiesare:
$(".myAjaxSubmitButton").on("click",function(event){});
$('.myAjaxSubmitButton').live('click',function(){});
20 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
});
If you wanted to receive JSON object, you would have to specify it in $.post() method with 4th parameter:
But remember. If you use CSRF validation of POST requests, also ajax post requests have to contain CSRF
string:
In PHP you can create this variable like this:
$csrfVar='YII_CSRF_TOKEN:"'.Yii::app()>request>csrfToken.'"';
And than you just have to paste it among $.post() variables, plus you can add "ajax" variable just for your needs:
function isAjax()
{
return ( Yii::app()>request>isAjaxRequest() or isset($_POST["ajax"]) or
isset($_GET["ajax"]) );
//Yii::app()>request>isAjaxRequest()shouldbeenought,butpeoplesayit'snot
reliable.
}
... Let me know if everyting works or suggest enhancements, I will love to learn something new :)
<table>
<tr>
<td>
<input type="text" name="quantity" value="a">
</td>
<td>
<select name="colour">
<option value="red">RED</option>
<option value="blue">BLUE</option>
</select>
21 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
But where to place the FORM that would make the function? Form can't be used, because of HTML validity. It
has to be faked in jQuery cca like this:
<script type="text/javascript">
$(document).ready(function(){
$(".rowSubmit").click(function()
{
var serialized=$(this).closest('tr').wrap('<form>').parent().serialize();
$.get('url2action',serialized,function(data){
//...canbeempty
//$.fancybox({content:data});
});
});
});
</script>
First we place the whole TR into a fictive FORM and than it can be serialized.
And a tip/trick for you. If you write $("my html code") or $(myStringVariableWithHtml) it will be turned into "jQuery
object" and you can append next jQuery functions. For example .serialize(), .html() etc.
I'm sorry, I had to split this article into more parts. Next is Yii for beginners 2
Total 13 comments
#14269
report it
Nice one!
22 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
Although I already started building my app and before that I was familiar with the MVC in theory, this article
made a couple of things clearer. I don't see the frameworks (or at least Yii) as a complex monster, which can
only be tamed by some advanced web developers only.
I disagree with one thing: "Very important thing is database. You should design it first. Before writing any
code."
It works for some projects, where the real world can be broken down in tables quite easy (typical scenarios
like let's say an app to track employees or whatever), but for more complex projects you often create some
data structures (even if you don't know exactly what you need and what are the data types, relations etc.), you
code a little, then you reflect, test, change the DB, code and test again... throw away the DB and start from
scratch but with a clear image what you need. And I think esp. for beginners, there is a lot of experimenting
and going back and forth.
An exception could be when you are not building your own app, but receive clear instructions (technical
specification) from a lead developer or customer and you just need to "translate" it into SQL and code.
#14072
report it
report it
report it
Fix line
Actual text: (Dropdownlist explanation)
$htmlOptions = array('width'=>'100','style'='color:red;')
is it better this one?
$htmlOptions = array('width'=>'100','style'=>'color:red;')
#13252
To: rackycz
Yes it was complicated to me too... that's why i want more example!
example like more than 5 relation table, and the parameter "through"
#13246
To nhexia:
To nhexia: What exactly would you like to know? Relations are complicated because of relation types:
BELONGS_TO / HAS_ONE ... I don't fully understand it neither. I always have to play with it for a long time.
Relations are not favourite part of Yii for me.
#13236
report it
report it
report it
report it
Excelent Work
Wonderful, tutorial if could some Video Tutorial that will be wonderful. But great work indeed.
#13155
#12161
To: Nabi
Thanks for idea, I will give it a try. It could save some lines of code which is always good :)
#11623
xSendFile()
Hi,
Thanks for this good article. I have a little note, that's you can use Yii::app()->request->xSendFile() instead of
23 of 24
28/05/2015 3:20 PM
http://www.yiiframework.com/wiki/250
header and readfile functions for send content of file to output for download it. Reffer to this article:
http://www.yiiframework.com/wiki/129/x-sendfile-serve-large-static-files-efficiently-from-web-applications/
Thanks
#10928
report it
report it
report it
report it
report it
Thanks Guys
Helo,
Very nice for beginners.Thanks for this really helpful.
#9714
thx!!
Thank you very much!! This help me!!!
#9361
Very helpfull
All what i whish i knew when i started. Good work.
#8823
Wonderful!
Great work! Thanks a lot for your great contribution!
#8179
tankssssssss
very usefull specially Recommended software and sites
Leave a comment
Please login to leave your comment.
About
Downloads
Documentation
About Yii
Framework
Features
Extensions
Tutorials
Performance
Demos
Class Reference
License
Logo
Guide 2.0
Contact Us
Yii Supporters
Development
Community
Contribute to Yii
Forum
Latest Updates
Live Chat
Report a Bug
News
Hall of Fame
Badges
24 of 24
28/05/2015 3:20 PM