In discuz, how to write the ct call? the following code is changed from DB to Ct, but the result is incorrect.
init();$data = $query = C::t('#portal_category')->fetch_all($catid);while($value=$this->fetch_array($data)){$data[]=$value;}print_r($data);?>
The following are the error messages.
Reply to discussion (solution)
C: t ('# portal_category'). do not add the # sign. it will think it is the table model under the plug-in directory, and an error will be reported, prompting you that you do not have the table model.
For example, C: t ('# qqconnect # common_member_qqconnect')-> insert ($ insert_arr );
Discuz will automatically go to the directory \ source \ plugin \ qqconnect \ table to find the table model file table_common_member_qqconnect.php.
Fetch_all ($ catid), $ catid is an array, and it is also a number
You do not need your while, so you can try it as follows:
//$catid=1;//$catid=array(1,2,3);$res = C::t('portal_category')->fetch_all($catid);echo "";print_r($res);echo "
";
C: t ('# portal_category'). do not add the # sign. it will think it is the table model under the plug-in directory, and an error will be reported, prompting you that you do not have the table model.
For example, C: t ('# qqconnect # common_member_qqconnect')-> insert ($ insert_arr );
Discuz will automatically go to the directory \ source \ plugin \ qqconnect \ table to find the table model file table_common_member_qqconnect.php.
Fetch_all ($ catid), $ catid is an array, and it is also a number
You do not need your while, so you can try it as follows:
//$catid=1;//$catid=array(1,2,3);$res = C::t('portal_category')->fetch_all($catid);echo "";print_r($res);echo "
";
In the above method, when the number in fetch_all (1) can be printed, but only one piece of data is output.
I tried to output all the data, so fetch_all ($ catid) was used)
However, the output is only an Array ();
Somehow,
The code is as follows:
init();$data = C::t('portal_category')->fetch_all($catid);print_r($data);?>
Er... I have told you before that there is no way to query all data in this table model. both fetch and fetch_all must have a condition that is the primary key catid. Therefore, we use DB to query all data, of course, you can also write a query method in the table model.
For example, open \ source \ class \ table \ table_portal_category.php and add the following method in the class (table_portal_category ).
public function my_fetch_all(){return DB::fetch_all("SELECT * FROM %t",array($this->_table));}
Call: $ data = C: t ('Portal _ category ')-> my_fetch_all (); // no parameter is required
However, I am still used to using DB for direct operations, which is more flexible.
Er... I have told you before that there is no way to query all data in this table model. both fetch and fetch_all must have a condition that is the primary key catid. Therefore, we use DB to query all data, of course, you can also write a query method in the table model.
For example, open \ source \ class \ table \ table_portal_category.php and add the following method in the class (table_portal_category ).
public function my_fetch_all(){return DB::fetch_all("SELECT * FROM %t",array($this->_table));}
Call: $ data = C: t ('Portal _ category ')-> my_fetch_all (); // no parameter is required
However, I am still used to using DB for direct operations, which is more flexible.
So I can also use DB,