我想使用form_validation类对输入进行验证,这将允许我在字段中输入数字或空值。
像这样:
$this->form_validation->set_rules('field[]','The field','numeric or empty|xss_clean');
Run Code Online (Sandbox Code Playgroud)
这有可能实现吗?
如何从控制器中的表单验证配置文件中获取数组?
应用/配置/ form_validation.php
我有一个想法是将表单验证数组保存到config.php中,而不是在form_validation.php中引用它.然后我将能够在控制器中获取它,并能够在验证中使用它.
有没有更好(直接)的方式?
我不知道为什么会这样,但也许有人在这里知道.我遇到了PHP method_exists()函数的问题.我传入一个对象和方法名称作为字符串,如下所示:
method_exists($question, "id")
Run Code Online (Sandbox Code Playgroud)
我对它做了一个var_dump,它说它返回false
echo var_dump(method_exists($question, "id")); // returns bool(false)
Run Code Online (Sandbox Code Playgroud)
但这是一个奇怪的部分.我用以下内容替换该行:
echo $question->id; // returns the id number
Run Code Online (Sandbox Code Playgroud)
那么如果对象方法有效,它怎么能返回false?
我在对象上做了一个var_dump,所以你可以看一看
object(stdClass)#19 (11) {
["id"]=> string(1) "4"
["question"]=> string(67) "This is a question?"
["answer_id"]=> string(1) "0"
["status"]=> string(6) "active"
["author_id"]=> string(1) "1"
["created_on"]=> string(10) "1323221575"
["last_edited"]=> string(10) "1324335140"
["order"]=> string(6) "random"
["answer_position"]=> string(1) "1"
["first_name"]=> string(3) "Joe"
["last_name"]=> string(8) "McMurray" }
Run Code Online (Sandbox Code Playgroud)
你可以马上看到第一个名为"id"的.那为什么它会返回假?
谢谢
当你有这样的方法时,有人可以告诉你该怎么做:
class Start extends CI_Controller
{
function foo($name)
{
//do something...
}
}
Run Code Online (Sandbox Code Playgroud)
并且网站的用户不传递任何参数,例如在地址栏中输入时:website/controller/foo /(no $ name parameter).
我想在发生这种情况时显示不同的视图,但我不知道如何检查这一点.
PS.我知道你可以使用$ this-> uri-> segment(); 而不是参数,但我宁愿不这样做.
谢谢
matches在CodeIgniter中运行表单验证时是否可以更改调用的输出?
我正在验证密码框验证密码.
array(
'field' => 'userPassword',
'label' => 'Password',
'rules' => 'trim|required|matches[userConfPassword]'
)
Run Code Online (Sandbox Code Playgroud)
但是当错误被触发时,它打印出来:
The Password field does not match the userConfPassword field.
Run Code Online (Sandbox Code Playgroud)
用户不知道userConfPassword手段是什么,我想将其更改为更友好的东西.阅读文档我无法找到方法.
我正在尝试使用带有codeigniter的sqlite数据库.我在其中创建了一个表,然后将数据库加载到配置文件中;
$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'sqlite';
$db['default']['dbprefix'] = '';
Run Code Online (Sandbox Code Playgroud)
并在autoload.php中自动加载了db库,但是我从控制器呈现的视图是空白的,即使没有显示任何错误.当我不自动加载此文件时,viw正确呈现.我不知道这里有什么问题.
我正在开发一个codeigniter项目,我正在尝试解决sql问题.我有一个查询更新我的表中的日期字段,它根本不更新它.
我有这张桌子
CREATE TABLE `Customer` (
`customer_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(55) NOT NULL DEFAULT '',
`last_name` varchar(55) NOT NULL DEFAULT '',
`city` varchar(255) DEFAULT '',
`state` char(2) DEFAULT '',
`zip` int(5) DEFAULT NULL,
`title` varchar(255) NOT NULL DEFAULT '',
`image` varchar(255) DEFAULT '',
`blurb` blob,
`end_date` date DEFAULT NULL,
`goal` int(11) DEFAULT NULL,
`paypal_acct_num` int(11) DEFAULT NULL,
`progress_bar` enum('full','half','none') DEFAULT NULL,
`page_views` int(11) NOT NULL DEFAULT '0',
`total_pages` int(11) NOT NULL DEFAULT '0',
`total_conversions` int(11) NOT NULL …Run Code Online (Sandbox Code Playgroud) 我只是有一个小问题,我找不到任何答案,因为我不确切知道如何在Google上制定它.
所以我从查询中返回了这个数组:
Array
(
[0] => Array
(
[aad3177ec0cbced7a15fae003bdd0ff3] => Array
(
[rowid] => aad3177ec0cbced7a15fae003bdd0ff3
[id] => 21
[qty] => 1
[price] => 176
[name] => KRUPS YY1305
[image] => utilities/images/products/p2070396dt.jpg
[description] => Menu simplifié pour une convivialité optimale.
[subtotal] => 176
)
)
)
Run Code Online (Sandbox Code Playgroud)
我想得到所有信息rowid,id,qty ...通过另一个变量的foreach循环存储它而不知道第二个数组的名称:'aad3177ec0cbced7a15fae003bdd0ff3'.我只想在用户注销时从存储在数据库中的购物车中检索文章.
那我该怎么说呢:
echo $myArray['0'][theNumberGoesHereAutomatically]['price'];
Run Code Online (Sandbox Code Playgroud)
理想情况下,我的代码看起来像这样:
foreach ($data2 as $cart){
$data = array(
'rowid' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['rowid'],
'id' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['id'],
'qty' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['qty'],
'price' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['price'],
'name' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['name'],
'image' => $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['image'],
'description'=> $cart_unserialized[$token]['aad3177ec0cbced7a15fae003bdd0ff3']['description'],
);
$this->cart->insert($data2); …Run Code Online (Sandbox Code Playgroud) 我试图通过使用$ this-> input-> post()从视图页面接收发布数组.但是,似乎CI无法做到这一点.有什么想法吗?
调节器
public function pub()
{
// the postArray is an array: $postArray['t1']=test1, $postArray['t2']=test2
$go=$this->input->post('postArray');
foreach ($go as $test){
echo $test['t1']; //show nothing
echo $test['t2']; //show nothing
}
//the following code would work if I sent the $postArray as a string variable
public function pub()
{
// the postArray is an string variable $postArray='test1'
$go=$this->input->post('postArray');
echo $go; //show test1
}
Run Code Online (Sandbox Code Playgroud)
感谢帮助.
更新:以下是我的视图页面中的Jquery代码
//postArray is an array
$.post('<?=base_url()?>/project_detail/pub', {'postArray':postArray},function(go)
{
alert(go);
})
Run Code Online (Sandbox Code Playgroud) 我在理解CI中应该保留哪些类时遇到问题.我正在构建一个描述/销售手机的应用程序.
我希望我的所有函数(即getphone,getdetails等)都驻留在一个名为Mobile的类中 - 我知道这个文件应该叫做Mobile.php并驻留在controllers文件夹中.
那么我可以在Mobile.php中拥有多个功能吗?例如
public function getphone() {
xxx
xx
xx
}
public function getdetails() {
xxx
xx
xx
}
Run Code Online (Sandbox Code Playgroud)
或者我需要将每个函数放在自己的类中吗?
我真的很感激看一些有效的示例代码.我已经浏览了几个小时的文档和谷歌,并尝试了URL中的各种变体来找到测试类,但没有太多运气!我甚至搞乱了路线和.htaccess ......
我想要实现的目标如下:
http:/// model/HTC-Desire /被重新路由到一个接受HTC-Desire作为参数的函数(因为我需要它进行数据库查找).默认控制器工作正常,但此后无法获得任何工作.
有任何想法吗?
谢谢