Yii

Yii Fixtures — Exception: Unknown property 'projects' for class 'ProjectTest'

好久不见. 提交于 2020-01-04 02:34:34
问题 I'm following the "Agile web application development with yii 1.1 and php5" book and i'm at the testing with fixtures section. I followed their code but i can't access to the fixture... I'm running my tests with phpunit and it returns me this c:\wamp\www\agileBook\protected\tests>phpunit unit/ProjectTest.php PHPUnit 3.6.11 by Sebastian Bergmann. Configuration read from C:\wamp\www\agileBook\protected\tests\phpunit.xml ←[31;1mE←[0m Time: 0 seconds, Memory: 5.75Mb There was 1 error: 1)

CDbCriteria parameters with regex character classes

送分小仙女□ 提交于 2020-01-04 02:07:15
问题 I'm trying to use CDbCriteria in Yii with a REGEXP condition. I'm using the MySQL markers for word boundaries, being [[:<:]] and [[:>:]] , however this seems to conflict with Yii because I get "Invalid parameter number: number of bound variables does not match number of tokens". I assume this is because the word boundary markers use a colon, which is also what is used for binding parameters. Is there a way around this? $criteria = new CDbCriteria; $criteria->addCondition('col regexp "[[:<:]]

Yii2 gii crud error Class 'app\models\Yii' not found

左心房为你撑大大i 提交于 2020-01-03 20:56:10
问题 I just installed yii2 advanced template, I created a model News and now I want to create the Crud (with gii), but when I click 'preview' I get this error. I did not change anything else in the advanced template. I'm using wamp PHP Fatal Error – yii\base\ErrorException Class 'app\models\Yii' not found 1. in C:\wamp\www\advanced\backend\models\News.php at line 44 2. in C:\wamp\www\advanced\vendor\yiisoft\yii2-gii\generators\crud\default\search.php – yii\gii\generators\crud\Generator:

Getting a “Headers already sent” error in Yii when rendering a view in beforeAction

放肆的年华 提交于 2020-01-03 13:07:02
问题 I've read about Yii2's handlers and I don't grasp how to use them properly for this case. Basically in my SiteController , I have: class SiteController extends \app\components\Controller { public function beforeAction($action) { // Makes some checks and if it's true, will render a file and stop execution of any action if (...) echo $this->render('standby'); return false; } return true; } // All my other actions here } This seems to work well and stop the execution, however I get the "Headers

Yii - Ajax Form with validations

社会主义新天地 提交于 2020-01-03 06:22:09
问题 I am a Yii Newbie, and I have the following problem. I have a form that is going to be like an admin - backend form. It will have loads of buttons each having their own "action" in the controller class. Now all I want to do is to validate the form elements, depending upon a "scenario" and to display appropriate error messages if all the parameters needed for the action is not filled in properly. Can some one show me how I can do this without me having to reload the page? [ I have found out a

Yii upon login show the username and logout button

走远了吗. 提交于 2020-01-03 04:36:14
问题 i want a logout button and the username in my header widget when the user logs into successfully. i have already created a header and a footer widget and dont want to create another one. i want the code by which i can get the username and logout button in the header. i am using yii rights and extensions too. please help me with this..!! i looked for the answer and someone had posted this stuff. i dont know where and how to use it. and this is the link of that solution. <?php if(Yii::app()-

Yii correct syntax for conditions in relation definitions

余生颓废 提交于 2020-01-03 04:32:12
问题 I'm struggling to get the correct syntax for a relation condition I'm trying to set. The main relation is set with the foreign key question_id, but also contained in the child table is the user_id column. I wish to return only records related to the logged in user. Here's what I've got so far- class SurveyQuestion extends CActiveRecord { ....... public function relations() { return array( 'answered_questions' => array(self::HAS_MANY, 'AnsweredQuestion', 'question_id', 'condition'=>"answered

Yii url manager only ID in url

不羁的心 提交于 2020-01-03 04:24:08
问题 i have in YII for example domain: www.example.com/product-url-1234 how to set rules in urlManager and how to use controller/action/id 回答1: If you want to use this url www.example.eu/product-url-1234 and suppose 'index' is the name of the action of the 'user' controller that will handle the request Then create a rule like '<id:.*?>'=>'user/index' Now if you will use Yii::app()->createUrl('user/index',array('id'=>'product-url-1234')) then it will give you the desired result. And if you Visit

Yii Async jsonp request

隐身守侯 提交于 2020-01-03 03:46:09
问题 I am new to the Yii PHP Framework so bear with me. I need to make a cross-domain JSONP request(from a non-yii app) to create a record in the Yii apps DB. Upon creating it should return Application/json content via getVisit The Controllers: public function actionGetVisit($id) { header('Content-type: application/json'); $visit = Visit::model()->findByPK((int)$id); echo CJSON::encode($visit); Yii::app()->end(); } /** * Creates a new model. * If creation is successful, the browser will be

model exist or not in YII using a custom function - Performance

风流意气都作罢 提交于 2020-01-03 03:39:07
问题 I am writing an REST API and need to check weather the given model name exist or not in the directory. 1 - http://example.com/RestApi/index.php/api/posts/ 2 - http://example.com/RestApi/index.php/api/post/ from these two, URL 1 is incorrect and URL 2 is correct (post). so i am taking this param and doing a search as following, $model = $m::model()->findAll($criteria); $m = TK::get('model'); when $m is incorrect, PHP warning include(posts.php): failed to open stream: No such file or directory