⚠ 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

Multilanguage solution crud?



stavgian
  • profile picture
  • Member

Posted 29 May 2012 - 15:27 PM

Can any one help me?

PAGES
|
|_id
|_title
|_content
|_meta_title
|_meta_description


PAGES_LANG
|
|_id
|_lang_code
|_field_id
|_title
|_content
|_meta_title
|_meta_description


Controller

function pages() {
$crud = new grocery_CRUD();
$crud->set_subject('Page') ->unset_delete();


if ($this->db->table_exists('pages_lang')) {
// Get languages from db
foreach($this->db_languages as $lang){
//default is the default language
if($lang->default != '1') //
{
$crud->add_action($lang->title, asset_url('images/'.$lang->code.'.png','marita'),'back/pages_lang/edit');
}
}
}
$this->template->build('admin/grocery_crud', $crud->render());



The pic shows my "pages" db table. The flags is actions...
Can anyone could tell my how to link each flag to my "pages_lang" db table and edit the selected row with the lang_code field related?
I don't know. Tell a idea..
Thanks

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

Posted 29 May 2012 - 20:29 PM

Well the solution is quite easy. You can do something similar to this:


function pages() {
$crud = new grocery_CRUD();
$crud->set_subject('Page') ->unset_delete();
if ($this->db->table_exists('pages_lang')) {
// Get languages from db
foreach($this->db_languages as $lang){
//default is the default language
if($lang->default != '1') //
{
//------ I only changed this line! ------------------------------------------------------\/
$crud->add_action($lang->title, asset_url('images/'.$lang->code.'.png','marita'),'back/insert_and_redirect/'.$lang->code);
}
}
}
$this->template->build('admin/grocery_crud', $crud->render());
}
function insert_and_redirect($lang_code,$field_id)
{
$this->db->where('lang_code',$lang_code);
$this->db->where('field_id',$field_id);
$page_db = $this->db->get('pages_lang');

if($page_db->num_rows() == 0)
{
$this->db->insert('pages_lang',array('lang_code' => $lang_code, 'field_id' => $field_id));
redirect(strtolower(__CLASS__).'/pages_lang/edit/'.$this->db->insert_id());
}
else
{
redirect(strtolower(__CLASS__).'/pages_lang/edit/'.$page_db->row()->id);
}
}

function pages_lang($operation = '') {
/* Just make sure that you don't want to redirect him at the page_lang page but at pages */
if($operation == '' || $operation == 'list')
{
redirect(strtolower(__CLASS__).'/pages');
}

$crud = new grocery_CRUD();

$crud->unset_fields('lang_code','field_id');

$this->template->build('admin/grocery_crud', $crud->render());
}

stavgian
  • profile picture
  • Member

Posted 29 May 2012 - 22:15 PM

[b]When i 'll be paid for this a will make you a donation.... [/b]
:lol:

Johnny.... Thanks A lot man..

stavgian
  • profile picture
  • Member

Posted 29 May 2012 - 22:45 PM

It worked perfectly....

Φίλε ευχαριστώ πάρα πολύ...


-- ----------------------------
-- Table structure for `pages_lang`
-- ----------------------------
DROP TABLE IF EXISTS `pages_lang`;
CREATE TABLE `pages_lang` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`lang_code` varchar(5) COLLATE utf8_bin NOT NULL,
`field_id` int(11) NOT NULL,
`title` varchar(255) CHARACTER SET utf8 NOT NULL,
`content` blob NOT NULL,
`meta_title` varchar(255) CHARACTER SET utf8 NOT NULL,
`meta_description` varchar(255) CHARACTER SET utf8 NOT NULL,
`meta_keywords` varchar(255) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;



On the images i kept visible to lang_code and the field_id to see that is working.

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

Posted 29 May 2012 - 22:54 PM

;)

stavgian
  • profile picture
  • Member

Posted 30 May 2012 - 11:43 AM

Could this be instead of redirect , a modal box or fancy?

tlc033
  • profile picture
  • Member

Posted 15 July 2013 - 11:18 AM

Hi. Could somebody explain how work this:

// Get languages from db
	  foreach($this->db_languages as $lang){
		//default is the default language
		if($lang->default != '1') //

THX in advance!


davidoster
  • profile picture
  • Member

Posted 15 July 2013 - 18:14 PM

It refers to this table,

PAGES_LANG
|
|_id
|_lang_code
|_field_id
|_title
|_content
|_meta_title
|_meta_description

 

 

where it iterates to each entry and tries to find the one that is default, the language tga $lang->default == '1'

Obviously you need to have one more field called 'default' within pages_lang in order to make this to work.


tlc033
  • profile picture
  • Member

Posted 15 July 2013 - 19:43 PM

It refers to this table,

PAGES_LANG
|
|_id
|_lang_code
|_field_id
|_title
|_content
|_meta_title
|_meta_description

 

 

where it iterates to each entry and tries to find the one that is default, the language tga $lang->default == '1'

Obviously you need to have one more field called 'default' within pages_lang in order to make this to work.

Hi, davidoster, thank you,.

I know how work foreach but i can't understund this "$this->db_languages" param.


davidoster
  • profile picture
  • Member

Posted 15 July 2013 - 20:32 PM

The $this->db_languages must be a class variable that John uses. Obviously this is a copy paste from one of his projects.


tlc033
  • profile picture
  • Member

Posted 15 July 2013 - 21:06 PM

ok. thx. davidosten