First i would like to say, Thanks for this great framework. Really makes coding a lot easier.
Few things i would like to point out and maybe ask
I was wondering how would i manage to make a global class that i can enter within any of my controllers? and where would i place it?
How can i make an error handler that i can just do new someexception('error here'); and it will show me the error from a template i make?
you have good documentation tough examples are missing to almost everything. If you can provide small bits of code examples to each method it will be very helpful.
For example i have a complete class that i wrote for various things i have for my application. Now i don't want to do
<?php
class IndexController extends CController
{
public $defaultAction='index';
public function actionIndex()
{
require_once('path/to/my/own/class/myclass.php'); <<
$general_functions = new mygeneral_functions; <<
$reader = Yii::app()->db->createCommand("SELECT * FROM gps_orders LIMIT 0,10")->query();
// each $row is an array representing a row of data
foreach($reader as $row)
{
$levels[] = $row['oid'];
}
CController::setPageTitle(Yii::t('test', 'Index'));
//Yii::app()->user->loginRequired();
// show the page
$this->render('Index');
}
}
in every controller i have, so instead maybe adding the entire class and it's methods to the application instance so i can do something like the database class does for example if i want to use Yii::app()->db->something i added
to my configuration file and then i can use Yii::app()->db->something where every i want in the application. Now i want to do the same thing but with my own class so i did:
'controllerMap'=>array(
'myclass'=>array(
'class'=>'myownclass'
),
// other controllers
),
in the configuration file, but where do i place my file that will load the 'myownclass' ? and what i did is valid?
not sure if i understood i would like for example to receive an input from a member then i check the incoming data, if it's empty then i would like to show an error but one of my own, it's not a 404, 400, 403 error just an internal one.
for example i used to do:
if(!$_POST['name'])
{
$myfunctions->error('please enter name');
}
How will i convert it to use the Yii structure?
OK you had some things planned for release for the end of the year which is in two day, I hope there it will include some example codes and examples upon methods.
another thing i wanted to know, i would like to make sure the member is logged in (for the ACP for example) if not then redirect him back to the login back. I can just insert the is loginRequired() in the begining of every controller, but i would like to avoid that and put it in one single place that will run all the time before any other action is taken and then i could verify that the member is actually logged in and then it passes just continue otherwise redirect to the login page.
Define a base controller class and extend all your controllers from this base class. In your base controller class, you override beforeAction() method and insert the code you need.
Providing your own error view is the simplest way to go. You only need to write a single error.php if you don't want to write other errorXXX views. Inside the view, you can check $type to see what kind of exception you are raising and display the corresponding content. Of course, you can always write your own error handler and replace the default one by setting it as the 'errorHandler' application component.
You should refer to existing error templates to see how to obtain different error information. For example, in order to display the error message, you just need to "echo $message". These are not explained clearly in current documentation.