⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

url_title



cangak
  • profile picture
  • Member

Posted 23 April 2012 - 06:00 AM

i have code like this


public function halaman()
{
$halaman = new grocery_CRUD();
$halaman->set_theme('datatables');
$halaman->set_table('halaman');
$halaman->columns('title','author','date','content','status');
$halaman->set_relation('author','user','user_nama');
$halaman->callback_before_insert(array($this,'seo'));
$output = $halaman->render();
$this->view($output);
}
function seo($post_array) {
//$this->load->library('url');
$post_array['url_title'] = url_title(post_array['url_title']);
return $post_array;
}


if there any error whit my call back
i try change
$post_array['url_title'] = url_title(post_array['url_title']);
to
$post_array['url_title'] = "tes";
work like a charm.
all i want to do is to make clean url using url_title from
http://codeigniter.c...url_helper.html

thanks and sorry for my bad english

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 23 April 2012 - 06:29 AM

You have wrong syntax, change:

function seo($post_array) {
//$this->load->library('url');
$post_array['url_title'] = url_title(post_array['url_title']);
return $post_array;
}


to:


function seo($post_array) {
$this->load->helper('url');
$post_array['url_title'] = url_title($post_array['url_title']);
return $post_array;
}


Its not post_array['url_title'] but $post_array['url_title']

cangak
  • profile picture
  • Member

Posted 23 April 2012 - 08:38 AM

[quote name='web-johnny' timestamp='1335162554' post='1401']
You have wrong syntax, change:

function seo($post_array) {
//$this->load->library('url');
$post_array['url_title'] = url_title(post_array['url_title']);
return $post_array;
}


to:


function seo($post_array) {
$this->load->helper('url');
$post_array['url_title'] = url_title($post_array['url_title']);
return $post_array;
}

Its not post_array['url_title'] but $post_array['url_title']
[/quote]
ups my bad sorry, i just write it not paste it from my code.

$post_array['url_title'] = url_title($post_array['url_title']);

i got [b]null[/b] value in databse
this is my databse

CREATE TABLE IF NOT EXISTS `halaman` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(200) DEFAULT NULL,
`url_title` varchar(200) DEFAULT NULL,
`author` int(11) DEFAULT '0',
`date` date DEFAULT NULL,
`content` text,
`status` enum('active','inactive') DEFAULT 'active',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;



are there any mistake in my code?
by the way thanks and 4 thumb up for the fast respond and one more this plugin save my time,

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 23 April 2012 - 18:19 PM

Everything seems to be fine. Can you copy-paste your all your code again?

cangak
  • profile picture
  • Member

Posted 24 April 2012 - 03:23 AM


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

class Dashboard extends CI_Controller {

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

/* Standard Libraries of codeigniter are required */
$this->load->database();
$this->load->helper('url');
/* ------------------ */

$this->load->library('grocery_CRUD');

} public function index()
{
echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
die();
}


function view($output = null)

{
$this->load->view('view.php',$output);
}
public function halaman()
{
$halaman = new grocery_CRUD();
$halaman->set_theme('datatables');
$halaman->set_table('halaman');
$halaman->columns('title','author','date','content','status');
$halaman->set_relation('author','user','user_nama');
$halaman->callback_before_insert(array($this,'seo'));
$output = $halaman->render();
$this->view($output);
}
function seo($post_array) {
//$this->load->helper('url');
$post_array['url_title'] = url_title($post_array['url_title']);
return $post_array;
}
}

/* End of file dashboard.php */
/* Location: ./application/controllers/dashboard.php */


and my sql structure

mysql> select * from halaman;
+----+------------------+-----------+--------+------------+---------------------------+--------+
| id | title | url_title | author | date | content | status |
+----+------------------+-----------+--------+------------+---------------------------+--------+
| 1 | lala lala lala | NULL | 3 | 2012-04-23 | <p>asdasd asdasdasd a</p> | active |
| 2 | asdasd asdasdas | NULL | 2 | 2012-04-23 | <p>asdasdasdad</p> | active |
+----+------------------+-----------+--------+------------+---------------------------+--------+

and actualy i have a little complect than insert url_title in database, i have to ceck it first are there any value that similiar with the user input, for a test i just insert url_tittle($post_array['url_title']) without cek it first, and it seem doesn work
try to find how to show error log on callback_before_insert find nothing.

and one more thing
i try this

$judul = "lalapo lalapo lalapo lalapo";
$post_array['url_title'] = url_title($judul);

it work

thanks before john hope i can donate a little for your project, couse it make me save thousand haur to develop a projeck

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 24 April 2012 - 06:25 AM

[member='cangak'] everything works fine for me. I copy your table , I add your functions and everything seems to work well. The only thing that I comment was the line:


$halaman->set_relation('author','user','user_nama');


so last chance try to comment this line and see if it will work. At least we will know where the problem is. If you still have this problem try to change the name of your variable let's say make it "urltitle" from "url_title" (just to try)

Also the validation is only for insert so make sure that you insert something and not updating it. So if you want to use it for both you can simply do this:


$halaman->callback_before_insert(array($this,'seo'));
$halaman->callback_before_update(array($this,'seo'));


AND LASTLY when you figure out the problem if you need some tutorial for how to check if the url_title is unique you can find it at: /topic/71-solved-set-rules-is-unique-doesnt-work/page__view__findpost__p__226

cangak
  • profile picture
  • Member

Posted 24 April 2012 - 08:56 AM

solve, thinking about deadline my head become cold like ice. hahahahha, this is ordinary my mistake


public function halaman()
{
$halaman = new grocery_CRUD();
$halaman->set_theme('datatables');
$halaman->set_table('halaman');
$halaman->columns('title','author','date','content','status');
$halaman->set_relation('author','user','user_nama');
$halaman->callback_before_insert(array($this,'seo'));
$output = $halaman->render();
$this->view($output);
}
function seo($post_array) {
//$this->load->helper('url');
//$post_array['url_title'] = url_title($post_array['url_title']); // << this line is my bad
//it should be
$post_array['url_title'] = url_title($post_array['title']); <<< hahhaah couse i grab from title field
return $post_array;
}


btw thanks before, let try the uniqe validation

sparrowfizow57
  • profile picture
  • Member

Posted 13 September 2013 - 09:23 AM

hi johnny and cangak..
ive similar problem
everything work fine but only for insert new record..
its not create the url for record that i edit/update..
ive add callback for both before_insert and before_update..
any idea though??
 
sorry, im a newbie in this crud world..
thx

sparrowfizow57
  • profile picture
  • Member

Posted 13 September 2013 - 09:24 AM

sorry this is my code