标签: controller

Codeigniter - uri段

我需要创建一个这样的网址:www.example.com/index.php/scheda/name-surname-id.html

所以我创建了Scheda控制器,这是代码:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Scheda extends CI_Controller{

    function __construct(){
        parent::__construct();
    }

    function index(){
        $name_scheda = $this->uri->segment(2);
        //i need only the id for the search into db
        $id = substr($name_scheda, strripos($name_scheda,'-')+1, strlen($name_scheda));

        echo "name:".$id;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我在地址栏中写下网址时,我得到了404 error...有人可以帮助我理解为什么吗?

controller codeigniter

0
推荐指数
1
解决办法
1761
查看次数

Kohana模板控制器,没有自动渲染

我有一个扩展Controller_Template的控制器(Controller_Product).在Controller_Product中我有一些动作(创建,编辑等),我需要渲染模板,但有些动作(例如保存,删除)必须返回一个json对象,所以我不需要模板来被渲染.我怎么解决这个问题?

我可以在保存删除操作中将$ this-> auto_render设置为FALSE ,但在这种情况下也会创建模板,即使没有渲染也是如此.我认为在我不需要它时加载模板并不是很优雅.

有什么建议?

templates controller kohana

0
推荐指数
1
解决办法
2919
查看次数

Prestashop - header.tpl- $ category类中无法访问的变量不可用

我目前正在学习模板变量,并试图了解它们的工作原理和含义.我已经在{$ category-> id_cms_category}上做了一个测试,我把它放在cms.tpl中,我得到了一个结果9,但是当我把它放在header.tpl或blockcms.tpl(左栏)中时,没有结果,这是空白的.

有人可以解释一下这是如何工作的,以及如何在不同的.tpl文件中获得相同的结果?我认为问题实际上是如何将$ category类分配给例如header.tpl.它与控制器有关吗?为什么我不能在任何地方使用某些变量?这是如何运作的?如果有人解释这一点,我会很高兴.我还在学习聪明.

variables controller class prestashop

0
推荐指数
1
解决办法
5216
查看次数

Ruby Rails,全局功能可供所有控制器使用

这可能是一个愚蠢的问题,你能为多个控制器提供一个功能吗?

我有2个控制器

class C1Controller < ActionController::Base
 def add(input_value)
  @output_value = input_value * 2
 end
end
Run Code Online (Sandbox Code Playgroud)

现在我想利用这个附加功能中的另一个控制器像这样

class C2Controller < ActionController::Base
 @new_value = add(2)
end
Run Code Online (Sandbox Code Playgroud)

ruby model-view-controller controller ruby-on-rails-3

0
推荐指数
1
解决办法
2869
查看次数

Active Admin:传递自定义页面的实例变量

我在ActiveAdmin中有一个名为statistics的自定义页面,我想在其中显示包含数据库数据的图表.

现在我使用了Gon gem并希望通过实例变量将数据传递给我的自定义页面.

通常,您会将gon行添加到索引操作中

class ProductsController < ApplicationController
  def index
    gon.rabl "app/views/products/index.json.rabl", as: "products"
  end
end
Run Code Online (Sandbox Code Playgroud)

但是我的自定义页面的活动管理员中没有控制器.我该怎么做?或者我是否必须通过仪表板执行此操作?

controller ruby-on-rails activeadmin

0
推荐指数
1
解决办法
3313
查看次数

另一个控制器内的MVC控制器?

我想知道是否有可能在MVC 3中的一个主要控制器中有几个嵌套控制器?例如:

public class AdminController : Controller
{
    public class PagesController : Controller
    {
    }
    //More controllers
}
Run Code Online (Sandbox Code Playgroud)

我试过这个但是无法让它工作,修改了我在global.asx中的路由,但仍然没有.如何AdminController在网址为例时调用正确的控制器:

/Admin/Pages/Index

c# asp.net-mvc controller

0
推荐指数
1
解决办法
381
查看次数

在Rails 3中保存时增加整数?

我在Rails 3应用程序中有以下代码:

 def like
    @suggestion = Suggestion.find(params[:id])
    Suggestion.update_all("votes = (votes + 1)")
    redirect_to suggestions_url
  end

  def dislike
    @suggestion = Suggestion.find(params[:id])
    Suggestion.update_all("votes = (votes - 1)")
    redirect_to suggestions_url
  end
Run Code Online (Sandbox Code Playgroud)

它正在工作,但不是更新当前的建议,而是更新所有建议.所以我改成了:

 def like
    @suggestion = Suggestion.find(params[:id])
    @suggestion.update_all("votes = (votes + 1)")
    redirect_to suggestions_url
  end

  def dislike
    @suggestion = Suggestion.find(params[:id])
    @suggestion.update_all("votes = (votes - 1)")
    redirect_to suggestions_url
  end
Run Code Online (Sandbox Code Playgroud)

但后来我得到:

undefined method `update_all' for #<Suggestion:0x007f87c2b918a0>
Run Code Online (Sandbox Code Playgroud)

所以然后我尝试了@suggestion.update_attribute(:votes, '1')但是将值重置为1而不是递增它.

实现这一目标的正确方法是什么?我只想让当前建议的整数(投票)在每次保存时增加/减少1.

我也试过以下没有运气:

def like
 @suggestion = Suggestion.find(params[:id])
 @suggestion.increment(:votes)
 redirect_to suggestions_url
end
Run Code Online (Sandbox Code Playgroud)

controller increment save ruby-on-rails-3

0
推荐指数
2
解决办法
2688
查看次数

如何在模型编辑上处理远程属性?ASP.Net MVC3

我在我的模型中使用远程属性来检查重复的页面标题如下

public class Page
{
  [Remote("CheckDuplicate", "Page", ErrorMessage = "Title already taken")]
  public string Title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在控制器中,我将根据" 检查 "结果返回JsonResult数据,如下所示:

public JsonResult CheckDuplicate(string Title)
{
   var result = db.Pages.Where(a => a.Title == Title).Count() == 0;
   return Json(result, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)

这在Create动作中工作正常,但问题是,它限制了我编辑现有页面,因为它正在检查相同的查询.

如何解决这个问题呢?请建议我

action controller model asp.net-mvc-3 remote-validation

0
推荐指数
1
解决办法
2759
查看次数

ruby on rails if语句总是返回true

控制器代码:

  def create

    if current_user.id != params[:friend_id]
      @return = { :curr_user_id => current_user.id, :params_id => params[:friend_id], :debug => 1 }
    else
      @return = { :curr_user_id => current_user.id, :params_id => params[:friend_id], :debug => 2 }
    end

    render :json => ActiveSupport::JSON.encode( @return )

  end
Run Code Online (Sandbox Code Playgroud)

所以current_user.id1并且params[:friend_id]通过ajax调用传递,它的值也是1

问题是它在这种情况下应该返回false时总是返回true ...是否有任何与被解析为字符串而不是整数的数字1有关?

ruby conditional controller ruby-on-rails ruby-on-rails-3

0
推荐指数
1
解决办法
473
查看次数

Rails控制器中的索引操作问题

可能是一个愚蠢的问题,所以我提前为此道歉:

我有一个Item Controller索引动作我用来显示所有items(duh).现在,我想过滤显示的项目(这里只是标题中有"鞋子"的项目).

不幸的是,我无法在索引操作下定义@item = Item.find(params [:id])语句.

我在ItemsController #index中得到了可怕的ActiveRecord :: RecordNotFound ----找不到没有ID错误的Item.

有任何想法吗?

物品控制器

def index
     @item = Item.find(params[:id])
     @items = Item.where(@item.title =~ /shoes/i).paginate(:page => params[:page], :per_page => 30)

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @items }
    end
  end
Run Code Online (Sandbox Code Playgroud)

ruby controller ruby-on-rails

0
推荐指数
1
解决办法
254
查看次数