Yii

How to create custom url in Yii [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-21 06:22:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to make user profile link like facebook for my web page How do i manage custom url for user profile like www.exampl.com/brito insted of www.exampl.com/user/profile/id/22 www.exampl.com/jhon insted of www.exampl.com/user/profile/id/31 www.exampl.com/piter insted of www.exampl.com/user/profile/id/66 I have done below code in my config/main.php file, now its works for this 3 static users only. how can i change

How to create custom url in Yii [duplicate]

倖福魔咒の 提交于 2019-12-21 06:21:39
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to make user profile link like facebook for my web page How do i manage custom url for user profile like www.exampl.com/brito insted of www.exampl.com/user/profile/id/22 www.exampl.com/jhon insted of www.exampl.com/user/profile/id/31 www.exampl.com/piter insted of www.exampl.com/user/profile/id/66 I have done below code in my config/main.php file, now its works for this 3 static users only. how can i change

yii 表单小部件的使用方式

狂风中的少年 提交于 2019-12-21 05:24:05
首先创建model层 因为要使用表单小部件 所以要加载相应的组件 这里需要的组件有 yii\widgets\ActiveForm 和 yii\helpers\Html 接下来在model定义的class里 写方法 首先我们要定义需要使用表单小部件的name值 不多说上代码 <?php /** * Created by PhpStorm. * User: jinlei * Date: 2017/5/10 * Time: 9:35 */ namespace frontend \ models ; use yii \ base \ Model ; use yii \ widgets \ ActiveForm ; use yii \ helpers \ Html ; class Form extends Model { public $name ; public $pwd ; public $sex ; public $hobby ; public $age ; public function rules ( ) { return [ ] ; } public function attributeLabels ( ) { return [ 'name' = > '用户名' , 'pwd' = > '密码' , 'sex' = > '性别' , 'hobby' = > '爱好' , 'age

How to add a textfield in form with out model class in YII?

家住魔仙堡 提交于 2019-12-21 05:08:14
问题 I need to add a text field in YII form in which i am not specify any model class name. But I need to process that value in the action method inside the controller class. ie I need to add a text field as <div class="row"> <input type="text" name="test" id="test" > </div> I add text field as <?php echo $form->textField($model['groupModel'],'group_name',array('size'=>60,'maxlength'=>128)); ?> But i do't want to specify any model name with the new text field.. Thanks in advance... 回答1: You can

Yii CDBCommand getText to show all variables in the SQL

六月ゝ 毕业季﹏ 提交于 2019-12-21 04:45:07
问题 I am using Yii's Yii::app()->db->createCommand() to build an SQL query. In order to view the SQL code that Yii generates, I am using the getText() method of CDBCommand. Problem is, when I use the getText() method on SQL code that contain parameters, for example: Yii::app()->db->createCommand() ->select("name") ->from('package') ->where('id=:id', array(':id'=>5)) ->queryRow(); the getText() method returns the following SQL: select name from package where id=:id instead of: select name from

How to bind array parameters in Yii framework?

天涯浪子 提交于 2019-12-21 04:12:49
问题 I have below code: $inputs = "1,2,3,4,5"; $sql = "SELECT * FROM obj WHERE id IN(:input)"; $commond = Yii::app()->db->createCommand($sql); $commond->bindValue(":input", $inputs , PDO::PARAM_STR); But the query result is incorrect. How to bind params for such IN condition? 回答1: for now use it like this $command = Yii::app()->db->createCommand() ->select() ->from('tableName') ->where(array('in', 'id', explode(',', $inputs))); I ll try to get back with $command->bindValue() method. 回答2: Having

Yii - External JS files Inlclude , registerScriptFile and publish

若如初见. 提交于 2019-12-21 04:08:41
问题 I am using YII framework for my web application . I have a question on registering external Java script file. Could some one please help me ? What is the best location to copy Java script file ( which folder ) I do see there are two ways to register that external Java script file First approach $baseUrl = Yii::app()->baseUrl; $cs = Yii::app()->getClientScript(); $cs->registerScriptFile($baseUrl.'/js/yourscript.js'); Second approch $cs=Yii::app()->getClientScript(); $cs->registerScriptFile(Yii

Loading core scripts such as jQuery in Yii 2

℡╲_俬逩灬. 提交于 2019-12-21 01:57:22
问题 I've been having a hard time trying to figure out how to load jQuery or other CORE scripts in Yii 2 . In Yii 1 it seemed this was the way: <?php Yii::app()->clientScript->registerCoreScript("jquery"); ?> In Yii 2, $app is a property of Yii, not a method, so the above naturally doesn't work, but changing it to: <?php Yii::$app->clientScript->registerCoreScript("jquery"); ?> produces this error: Getting unknown property: yii\web\Application::clientScript I couldn't find any documentation for

How to use Yii with a multilingual database model?

你说的曾经没有我的故事 提交于 2019-12-20 19:31:33
问题 I’m having a problem getting the data from my database which I created to be completely multilingual, and I hope someone here can help me. I’ve split up all my tables in 2 parts; the “universal” table (does not contain any text that needs to be translated) and the table which contains all the fields that need to be translated with their translations. Example tables: base_material id picture base_material_i18n base_material_id localization_id name description review_status review_notes

YII 关联表查询

六月ゝ 毕业季﹏ 提交于 2019-12-20 18:10:02
AR模型中可以通过relations()方法建立关系 class B public function relations() { return array( 'a'=>array(self::BELONGS_TO, 'A', 'id') ); } 这样一对一关系就建立好了。 $b = B::model()->find($criteria); $a = $b->a; 第二步是利用一个lazyFinder重新查询结构赋值给$a; 四种关系: 关系 定义 例子 BELONGS_TO A和B的关系是一对多,那么B属于A Post属于User HAS_MANY A和B之间的关系是一对多,那么A有多个B User有多个Post HAS_ONE 这是HAS_MANY的一种特殊情况,A至多有一个B User至多有一个Profile MANY_MANY 这个对应多对多的情况,在AR里会将多对多以BELONGS_TO和HAS_MANY的组合来解释 Post和Category 在AR中通过重写CActiveRecord类的relations()方法来申明关系;这个方法返回一个关系配置的数组;一个数组无素代表一个单独的关系,格式如下: 'VarName'=>array('RelationType','ClassName','ForeignKey', ...additional options) Var