我认为这很简单.
我有一个Codeigniter函数,它从表单中获取输入并将它们插入到数据库中.我想Ajax化这个过程.目前函数的第一行从表单中获取id字段 - 我需要更改它以从Ajax帖子(它引用包含必要值的表单中的隐藏字段)获取id字段.我该怎么办?
我的Codeigniter控制器功能
function add()
{
$product = $this->products_model->get($this->input->post('id'));
$insert = array(
'id' => $this->input->post('id'),
'qty' => 1,
'price' => $product->price,
'size' => $product->size,
'name' => $product->name
);
$this->cart->insert($insert);
redirect('home');
}
Run Code Online (Sandbox Code Playgroud)
和jQuery Ajax函数一样
$("#form").submit(function(){
var dataString = $("input#id")
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "/home/add",
data: dataString,
success: function() {
}
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
一如既往,非常感谢提前.
我目前在我的应用程序中有这个代码:
def comment_poster(comment)
if comment.user
"posted by #{comment.user.username} #{time_ago_in_words(comment.created_at)} ago"
else
"posted by anonymous"
end
end
Run Code Online (Sandbox Code Playgroud)
但是,这只适用于我在几秒钟前和几年前发布的情况:
posted by teejay about 1 year ago
posted by teejay about 1 month ago
Run Code Online (Sandbox Code Playgroud)
当我几天前编辑created_at值时,它给了我:
posted by thorpe {{count}} days ago
Run Code Online (Sandbox Code Playgroud)
我该怎么办才能使它发挥作用而失去它 {{count}}
编辑:如果这意味着什么,我正在使用Rails 2.3.5
编辑:#2
我通过粘贴固定的问题这段代码在config/locales/en.yml
datetime:
distance_in_words:
half_a_minute: "half a minute"
less_than_x_seconds:
one: "less than 1 second"
other: "less than %{count} seconds"
x_seconds:
one: "1 second"
other: "%{count} seconds"
less_than_x_minutes:
one: "less than a minute"
other: "less than …Run Code Online (Sandbox Code Playgroud) 我有一个房地产经纪人客户希望网站列出他正在销售的房产.虽然有很棒的第三方网络应用可以做到这一点,但他坚决要求我为他重新创建一个简单的自定义网站.
我可以使用像MVC,数据访问对象和数据绑定控制器附带的Code Igniter之类的php框架快速完成此操作.数据库很简单:
t_page:通用内容页面
t_property:对于市场上的每个房产,都有地址,价格,#床房等字段.
然而,客户已经听到很多关于Wordpress的好东西,并强烈建议我用它建立他的房地产网站.我只使用Wordpress来创建博客和相对简单的网站.所以我不知道它作为一个房地产物业内容管理系统是多么有效,或者用户根据诸如"卧室,平方英尺,地下室完成等......"等属性搜索房地产物业的效果如何.
所以我的问题是,用Wordpress建立一个房地产经纪人网站是个好主意吗?或者我应该更努力地说服他使用像Code Igniter这样的Web框架来构建它?
我有从数据库编码字符的问题.我正在使用带有win1250编码的Postgres,但无论我放在core.php中(现在我有这行代码):
Configure::write('App.encoding', 'iso-8859-1');
Run Code Online (Sandbox Code Playgroud)
有时它会给我一些来自数据库的奇怪信件,例如ÈindsteadofČ.我能做些什么来获得正确的编码.
注意:我无法编辑或更改任何数据库.
我可以使用一个codeigniter框架目录来创建多个应用程序吗?
因为似乎我必须为不同的应用程序提供单独的codeigniter文件夹实例.我希望能够在一个地方调整一些代码(通用的类),并且我使用codeigniter创建的每个应用程序都会受到影响.
你可以做到这一点.
我在javascript中有以下代码
var result = {
'org.apache.struts' : '4567ty5y7u8j89hjk789',
'firstName' : 'Thorpe',
'surName' : 'Obazee'
}
Run Code Online (Sandbox Code Playgroud)
当我尝试阅读结果时:
// this works
sys.puts(result.firstName) // returns Thorpe
sys.puts(result.surName) // returns Obazee
Run Code Online (Sandbox Code Playgroud)
当我读到其他财产时,问题就来了
sys.puts(result.org.apache.struts) // return an error
Run Code Online (Sandbox Code Playgroud)
错误:预期'TypeError:无法读取未定义的属性'apache'
我该怎么读这个以便我可以访问我提供的信息?
我正在使用CodeIgniter的会话库,它在服务器端非常容易访问.在客户端,会话cookie看起来像这样(我加粗了我感兴趣的部分):
一个:7:{S:10: "的session_id"; S:32: "47fe66476b098ff092f2fbdddfa53ffa"; S:10: "IP地址"; S:9: "127.0.0.1"; S:10: "USER_AGENT"; S:50 :"Mozilla/5.0(Windows; U; Windows NT 5.1; en-US; rv"; s:13:"last_activity"; s:10:"1296180527"; s:7:"user_id"; s:3:" 895"; s:8:"username"; s:8:"Summer N" ; s:6:"status"; s:1:"1";} fc0f1e75c097be7970b815a630bf33ef
咳咳.我想访问"用户名",目前设置为8个字符的字符串Summer N.是否有一种明显的方法可以在javascript中解析它?我应该使用正则表达式吗?或者更好的方法是使用更简单的数据格式创建我自己的"用户"cookie,并让CI的会话分别做自己的事情?
Codeigniter v2.0于28日发布.我只是设置了一个全新安装并尝试从url中删除index.php.我使用相同的apache站点可用配置,htaccess和codeigniter配置.
当我排除index.php时,Codeignter只加载routes.php中定义的默认控制器.
例如
这是我对相关网站的apache配置.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName myurl.com
DocumentRoot /var/www/myurl.com
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /var/www/myurl.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ …Run Code Online (Sandbox Code Playgroud) 我目前有这个:
cart = [{"40"=>[{"size"=>"1", "count"=>1, "variation"=>nil, "style"=>"3"}]}, {"40"=>[{"size"=>"2", "count"=>1, "variation"=>nil, "style"=>"3"}]}]
Run Code Online (Sandbox Code Playgroud)
如何搜索此数组并查明"40"是否存在?
$app->post('/', function () use ($app) {
$email = new Input('email');
$email->getValidatorChain()
->addValidator(new Validator\EmailAddress());
$password = new Input('name');
$password->getValidatorChain()
->addValidator(new Validator\StringLength(1));
$inputFilter = new InputFilter();
$inputFilter->add($email)
->add($password)
->setData($_POST);
if ($inputFilter->isValid()) {
// do stuff
$app->redirect('/');
} else {
$field_errors = array();
foreach ($inputFilter->getInvalidInput() as $field => $error) {
foreach ($error->getMessages() as $message) {
$field_errors[] = str_replace('Value', ucfirst($field), $message);
}
}
$app->render('index.php', array('field_errors' => $field_errors));
}
});
Run Code Online (Sandbox Code Playgroud)
我目前使用Slim Framework并使用Zend InputFilter获得上述代码.但是,我想检索错误消息.我不断收到"价值......"所以我做了str_replace他们获得Email is not a valid email象下面这样:
$field_errors = array(); …Run Code Online (Sandbox Code Playgroud)