【问题标题】:How will I connect my search query to my ionic app?如何将我的搜索查询连接到我的 ionic 应用程序?
【发布时间】:2016-05-07 21:07:12
【问题描述】:

我有这个查询用于搜索多个数据,但它只是静态的

user_model.php (coeigniter)

public function get_halal()
{
    $term = "Buko,Beef,Sugar";
    $terms = explode(',', $term);

    foreach($terms as $term){

    $this->db->select('*');
    $this->db->from('recipe');
    $this->db->join('menu', 'menu.recipe_id = recipe.recipe_id');
    $this->db->join('ingredient', 'ingredient.ingredient_id = menu.ingredient_id');
    $this->db->where('menu.category_id = 2');
    $this->db->like('ingredient.name', $term);
    $query = $this->db->get()->result();
   }
    return $query;
}

我希望它是动态的并连接到我的 ionic 应用程序。我该怎么做?

【问题讨论】:

  • 解析$term作为参数?

标签: php codeigniter ionic-framework


【解决方案1】:

当你想创建一个函数(或一个类)时,首先你必须抽象出这个问题,以了解这个函数在不同的上下文中有多大的用处。没有规则,这取决于您的背景和目标。

在您的示例中,即该函数为术语“Buko”、“Beef”和“Sugar”返回一个数据库查询对象(事实上,仅适用于“Sugar”)。如果你以这种方式修改你的函数:

public function get_halal( $what )

您可以重复使用该功能来搜索任何术语。

如果你这样修改函数:

public function get_halal( $what )
{
    if( is_array($what) ) ...
    else                  ...

您可以使用相同的功能来搜索一个或多个字词。

如果你这样修改函数:

public function get_halal( $what, $where )

您可以在各个领域搜索一个词。

有很多可能性,这是编码的最大乐趣。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 2016-07-18
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多