Search code examples
phpcodeigniter-2phpactiverecord

redirect deleted products from database asigning them a new ID


I need to make some redirects for some products which has been deleted from database.

I get the product from database this way:


    public function show( $prod_id=null){
      $produs=Product::find(array('conditions' => array('product_id = ?', $prod_id)));
    }

and I want to create some kind of array with the ID's that are deleted and set them a new ID for an existing product. I have made something like this (1726 is the deleted ID and the other one, 369 is the new ID):


    $products = array(  '1726' => 369,
                        '1716' => 1650,
             );


Solution

  • public function show( $prod_id=null ) {
        $products = array(  '1726' => 369,
                        '1716' => 1650,
         );
    
        if ( isset($products[ $prod_id ]) ) {
            $prod_id = $products[ $prod_id ];
        }
    
        $produs=Product::find(array('conditions' => array('product_id = ?', $prod_id)));
    }