Welcome Guest, Not a member yet? Register   Sign In
  AR library : keep method order close to actual sql statement or not
Posted by: El Forum - 06-09-2008, 02:05 AM - Replies (2)

[eluser]xwero[/eluser]
i was wondering how other developers are using the AR library methods. You can do

Code:
$query = $this->db->select('field')->from('table')->where('field',$value)->get()
Or you can write it as
Code:
$this->db->select('field');
$query = $this->db->get_where('table',array('field'=>$value));

Which do you prefer and why?


  How do i set the basepath, or base_url, or? what? ugh..
Posted by: El Forum - 06-09-2008, 12:53 AM - Replies (1)

[eluser]Unknown[/eluser]
This is my first day with CI, I've just discovered it and I'm quite excited to see all that CI can do.

I was following the video tutorials, when I came upon scaffolding in the "build a blog" video, things went wrong so I did a search and discovered scaffolding is no longer used. etc. etc. My problem is that it's pointing me to this url:
http://127.0.0.1/CodeIgniter/index.php/blog/comments

when it should be pointing me towards this url:
http://mywebsitename.com/index.php/blog/comments

so this part: "http://127.0.0.1/CodeIgniter/"
should be this: "http://mywebsitename.com/"

I read something about a basepath, or baseurl I need to change, but I can't find it?


  InkType Powered Sites?
Posted by: El Forum - 06-09-2008, 12:31 AM - Replies (1)

[eluser]Developer13[/eluser]
Hi all -

I know that some of you are using InkType in a production environment despite its alpha development status. If you are and if you would like to showcase the site, please let me know and I'll put a link to your site on http://www.inktype.org/page/sites-using-inktype/

Thanks!


  Select AND / OR problem
Posted by: El Forum - 06-09-2008, 12:29 AM - Replies (8)

[eluser]Cambo[/eluser]
Hi Resident Gurus

I am generating this query for a search using Active Record

SELECT `productID` FROM (`product`) WHERE `productName` LIKE 'clear %' OR `productName` LIKE '% clear %' OR `productName` LIKE '% clear' AND `productName` LIKE 'file %' OR `productName` LIKE '% file %' OR `productName` LIKE '% file'

However, it is not formatting correctly. What I want is:

SELECT `productID` FROM (`product`) WHERE (`productName` LIKE 'clear %' OR `productName` LIKE '% clear %' OR `productName` LIKE '% clear') AND (`productName` LIKE 'file %' OR `productName` LIKE '% file %' OR `productName` LIKE '% file')

Notice the brackets around the LIKE clauses?

How do I do that?

TIA
Cambo


  weird bug on database model [ci 1.6.2]
Posted by: El Forum - 06-09-2008, 12:16 AM - Replies (5)

[eluser]adwin[/eluser]
Hi .. I found a bug that not always happened in my model

i use ci 1.6.2

here is my code

Code:
function save()
        {
            $this->db->set('measureid',$this->measureid);
            $this->db->set('goodsid',$this->goodsid);
            $this->db->set('poid',$this->poid);
            $this->db->set('qty',$this->qty);
            $this->db->set('qty0',$this->qty0);
            
            $this->db->set('unitprice',$this->unitprice);
            $this->db->set('discount',$this->discount);
            $this->db->set('total', $this->calculatetotal());
            
            $this->db->trans_begin();
            $status = '';  
            if($this->id != 0)
            {
                $this->db->where('id',$this->id);
                $status = $this->db->update($this->_table);
            }else
            {
                $status = $this->db->insert($this->_table);
                $this->id = $this->db->insert_id() ;
            }
            
            if(!$this->checkstatus($status,$this->_table)){
                echo $this->goodsid.' <br/>';
                echo $this->db->last_query();
                return false;
            }

            if(!$this->updateHeader($this->poid))
                return false;      

            if ($this->db->trans_status()===FALSE){
              return $this->rolllback();
            } else {
              $this->db->trans_commit();
              return true;
            }
        }

as you can see, there is
Code:
$this->db->set('measureid',$this->measureid);
$this->db->set('goodsid',$this->goodsid);
on the top of the db->set();

measureid and goodsid is linked with other table (foreign keys)

when I did insert it produce the error because measureid or goodsid not included into the insert sql.

here is the error:
Code:
Cannot add or update a child row: a foreign key constraint fails (`ci/podt`, CONSTRAINT `podt_ibfk_2` FOREIGN KEY (`goodsid`) REFERENCES `mtgoods` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
SQL : INSERT INTO `podt` (`measureid`, `qty`, `unitprice`, `discount`, `total`) VALUES ('1', 20, '30000', '300', 599700)

as you can see on my code, i have set the goodsid and measureid right ?


  MVC Structure Question
Posted by: El Forum - 06-08-2008, 10:41 PM - Replies (1)

[eluser]drshields[/eluser]
This is a general question relating to MVC development.

I want to add a value to a database if the value doesn't currently exist, and then return the insert id of that entry. If the value already exists, just return the id of that entry.

Do I do the logic piece of that in the controller, or in the model? Doing the controller requires two functions, where doing it in the model requires only one.

EXAMPLE

From the controller, I call one function to see if it exists, and another to add it if it doesn't exist:

Code:
if ($this->database_model->value_exists($some_value) == NULL)
{
   $new_id = $this->database_model->add_value($something);
}

Now if I put the logic in the model, my controller looks like this:

Code:
$value_id = get_value($something);

In my model:

Code:
function get_value($something)
{
  // do query to get value.  if it exists, return the id
  // if value doesn't exist, insert $something and return id
}

What is the "proper" way to do this? Does it matter?


  index.php keep showing
Posted by: El Forum - 06-08-2008, 10:06 PM - Replies (2)

[eluser]EEssam[/eluser]
Hello,

I'm coding in http://localhost/somefolder so I created a .htaccess file like the following:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

I copied that from CI docs, I just added the ./ on the last line, and it's working but the all the links are showing the index.php again! If I remove the index.php manually the links work as well.

So, why index.php is being added and how can I get rid of it forever?

Thanks.


  What's wrong with $this->db->insert('comment', $_POST);
Posted by: El Forum - 06-08-2008, 09:13 PM - Replies (1)

[eluser]EEssam[/eluser]
Hello,

I just finished watching the great CI video tutorials and the guy on the tutorial said that the following line of code should be cleaned for security in real world programming or something like that:

$this->db->insert('comment', $_POST);

Doesn't CI clean the $_POST array automatically? If not, what I should do to safely insert comments using this method (I mean passing the whole array to $this->db->insert)?

Please advise.


  What's the practical way to load header and footer
Posted by: El Forum - 06-08-2008, 09:04 PM - Replies (13)

[eluser]EEssam[/eluser]
Hello,

I'm wondering what is the most practical way to load a header and a footer.

I know I can do:

$this->load->view('header');
$this->load->view('myview');
$this->load->view('footer');

But I just don't see how I should call this in almost each function in my controller classes.

Please advise.


  HTML Helper Extended - script_tag() added (Add .js files easily)
Posted by: El Forum - 06-08-2008, 04:22 PM - Replies (2)

[eluser]Isern Palaus[/eluser]
Hello,

I was programming a website today (I was 2 months without touching any code) and I've seen that now CodeIgniter has a lot of features and one of them is the link_tag() for adding CSS files.

But... What about the JavaScript? Here is a literaly modification of the link_tag() for using with [removed]

File: /application/helpers/my_html_helper.php

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Script
*
* Generates a script inclusion of a JavaScript file
* Based on the CodeIgniters original Link Tag.
*
* Author(s): Isern Palaus <[email protected]>
*
* @access    public
* @param    mixed    javascript sources or an array
* @param    string    language
* @param    string    type
* @param    boolean    should index_page be added to the javascript path
* @return    string
*/    

if ( ! function_exists('script_tag'))
{
    function script_tag($src = '', $language = 'javascript', $type = 'text/javascript', $index_page = FALSE)
    {
        $CI =& get_instance();

        $script = '$v)
            {
                if ($k == 'src' AND strpos($v, '://') === FALSE)
                {
                    if ($index_page === TRUE)
                    {
                        $script .= ' src="'.$CI->config->site_url($v).'"';
                    }
                    else
                    {
                        $script .= ' src="'.$CI->config->slash_item('base_url').$v.'"';
                    }
                }
                else
                {
                    $script .= "$k=\"$v\"";
                }
            }
            
            $script .= ">\n";
        }
        else
        {
            if ( strpos($src, '://') !== FALSE)
            {
                $script .= ' src="'.$src.'" ';
            }
            elseif ($index_page === TRUE)
            {
                $script .= ' src="'.$CI->config->site_url($src).'" ';
            }
            else
            {
                $script .= ' src="'.$CI->config->slash_item('base_url').$src.'" ';
            }
                
            $script .= 'language="'.$language.'" type="'.$type.'"';
            
            $script .= '>'."\n";
        }

    
        return $script;
    }
}
?&gt;

We only need to write...

Code:
&lt;?=script_tag('content/js/jquery-latest.js');?&gt;

This is my first CodeIgniter aportation, wish you like it.

Sorry for my school english :-).

Regards,
-- Isern Palaus


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Update to v4.5.1, same us...
by kenjis
5 hours ago
Reading a session variabl...
by kenjis
9 hours ago
Codeigniter 4 extend core...
by Semsion
Yesterday, 05:08 AM
v4.5.1 Bug Fix Released
by lokman
04-16-2024, 02:12 PM
problem with textarea
by Nitin Arora
04-16-2024, 05:07 AM
Showing pdf on browser
by aarefi
04-16-2024, 04:38 AM
[4.5.1] Disabling the deb...
by keto
04-16-2024, 02:43 AM
directory structure
by badger
04-16-2024, 01:49 AM
Redirect with error vali...
by pippuccio76
04-16-2024, 01:41 AM
Pass custom variables to ...
by InsiteFX
04-15-2024, 11:17 PM

Forum Statistics
» Members: 84,395
» Latest member: fcb8vnlife
» Forum threads: 77,555
» Forum posts: 375,884

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB