• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bancha, Open-source CMS

#31
[eluser]Nicholas Valbusa[/eluser]
[quote author="kkzhi" date="1335186742"][quote author="Nicholas Valbusa" date="1335177922"]
Hello,
I used NivoSlider, it's really easy to use: http://nivo.dev7studios.com/

To extract the contents, just create a content type with an images field and extract it on the homepage view as follows:

Code:
$teasers = find('Teasers')->limit(10)->order_by('date_update', 'DESC')->get();

foreach ($teasers as $teaser) {
    $imgs = $teaser->get('teaser_image'); //images field
    $path = $imgs[0]->path; //the first image
    echo '<img src="' . $path . '" />'; //prints the image
}

Nicholas[/quote]

Hello Nicholas, thx for the explanation, but its seems like i missunderstood or just dont get it cause it give a warning message like this
Code:
A PHP Error was encountered

Severity: Notice

Message: Uninitialized string offset: 0

Filename: templates/homepage.php

Line Number: 25
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: templates/homepage.php

Line Number: 25

can u tell me why? thanks Smile[/quote]

Hello, you're likely trying to get a property on a string/array.
Could you please send me your homepage.php template so I can help you?

Nicholas

#32
[eluser]kkzhi[/eluser]
[quote author="Nicholas Valbusa" date="1335188282"]

Hello, you're likely trying to get a property on a string/array.
Could you please send me your homepage.php template so I can help you?

Nicholas[/quote]

Oke this is it

Code:
&lt;?php
/**
* Default website home template
*
* @package  Bancha
* @author  Nicholas Valbusa - [email protected] - @squallstar
* @copyright Copyright (c) 2011-2012, Squallstar
* @license  GNU/GPL (General Public License)
* @link  http://squallstar.it
*
*/

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

render('header'); ?&gt;

<h1>This is the homepage of your website.</h1>

<p>This script is located here: <strong>themes/&lt;?php echo $this->view->theme; ?&gt;/views/templates/homepage.php</strong></p>
<p>Note that this is also a Record of type <strong>Menu</strong> marked as <strong>website homepage</strong> on the settings.</p>
&lt;?php $teasers = find('Teasers')->limit(10)->order_by('date_update', 'DESC')->get();

foreach ($teasers as $teaser) {
    $imgs = $teaser->get('teaser_image'); //images field
    $path = $imgs[0]->path; //the first image
    echo '<img src="' . $path . '" />'; //prints the image
}
?&gt;
&lt;?php
if (type('Blog')) {

$posts = find('Blog')->limit(10)->order_by('date_publish', 'DESC')->get(); ?&gt;

<h2>Some posts</h2>

<ul>
&lt;?php
foreach ($posts as $post)
{
  ?&gt;<li><a href="&lt;?php echo semantic_url($post); ?&gt;">&lt;?php echo $post->get('title'); ?&gt;</a></li>
  &lt;?php
}
?&gt;
</ul>

&lt;?php
}

render('footer');

i made in a content types("teasers.xml") and i change field id text area to field id="teaser_image" recording to script that u give it to me
but seems like it didn't produce any $path in return.
and where i put a nivo slider pack that i download before? sorry for the question, i'm just newbie in this Sad

#33
[eluser]Nicholas Valbusa[/eluser]
[quote author="kkzhi" date="1335190866"]

Oke this is it

Code:
....

i made in a content types("teasers.xml") and i change field id text area to field id="teaser_image" recording to script that u give it to me
but seems like it didn't produce any $path in return.
and where i put a nivo slider pack that i download before? sorry for the question, i'm just newbie in this Sad
[/quote]
Hello, did you declared the image field like this:
http://docs.getbancha.com/content-types/...mages.html

If yes, the problem is that you need to check the number of elements in $img before calling an attribute of a null object:

Code:
$imgs = $teaser->get('teaser_image'); //images field
if (is_array($imgs) && count($imgs)) {
    $path = $imgs[0]->path; //the first image
    echo '<img src="' . $path . '" />'; //prints the image
}


#34
[eluser]kkzhi[/eluser]
[quote author="Nicholas Valbusa" date="1335192208"]
Hello, did you declared the image field like this:
http://docs.getbancha.com/content-types/...mages.html

If yes, the problem is that you need to check the number of elements in $img before calling an attribute of a null object:

Code:
...

[/quote]

yes i declared the image field just like http://docs.getbancha.com/content-types/...mages.html
and after i type this code :
Code:
$imgs = $teaser->get('teaser_image'); //images field
if (is_array($imgs) && count($imgs)) {
    $path = $imgs[0]->path; //the first image
    echo '<img src="' . $path . '" />'; //prints the image
}
the error warning was missing but still no image show up just like $teasers didn't produce anything, there's anything i should check in more?

#35
[eluser]Nicholas Valbusa[/eluser]
[quote author="kkzhi" date="1335194584"][quote author="Nicholas Valbusa" date="1335192208"]
Hello, did you declared the image field like this:
http://docs.getbancha.com/content-types/...mages.html

If yes, the problem is that you need to check the number of elements in $img before calling an attribute of a null object:

Code:
...

[/quote]

yes i declared the image field just like http://docs.getbancha.com/content-types/...mages.html
and after i type this code :
Code:
$imgs = $teaser->get('teaser_image'); //images field
if (is_array($imgs) && count($imgs)) {
    $path = $imgs[0]->path; //the first image
    echo '<img src="' . $path . '" />'; //prints the image
}
the error warning was missing but still no image show up just like $teasers didn't produce anything, there's anything i should check in more?[/quote]
Are you sure that you created at least one record of type "Teaser" with an image from the administration? Smile
If yes, you can try to check what the record contains (into the foreach cycle) like this:

Code:
debug($teaser);
//or...
debug($teaser->get('your_image_field_id'));

#36
[eluser]kkzhi[/eluser]
[quote author="Nicholas Valbusa" date="1335195796"]
Are you sure that you created at least one record of type "Teaser" with an image from the administration? Smile
If yes, you can try to check what the record contains (into the foreach cycle) like this:

Code:
debug($teaser);
//or...
debug($teaser->get('your_image_field_id'));
[/quote]

yes i am sure i created a record, and when i debug it produce
Code:
-------------------
string(0) ""
-------------------

-------------------
string(0) ""
-------------------

am i wrong in wrote xml file?
cos i check with firebug in administration panel , the record (upload field) produce
Code:
&lt;input type="file" multiple=" " value="" name="[b]teaser_image[][/b]"&gt;
really confusing (=_=')

#37
[eluser]Nicholas Valbusa[/eluser]
[quote author="kkzhi" date="1335197933"][quote author="Nicholas Valbusa" date="1335195796"](...) really confusing (=_=')[/quote]
Please send me the image field xml definition so I can check if is correct.

#38
[eluser]kkzhi[/eluser]
[quote author="Nicholas Valbusa" date="1335195796"]
Please send me the image field xml definition so I can check if is correct.[/quote]

ok this is it

Code:
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- generator="bancha-1.1.1" --&gt;
<content id="6">
<name>Teasers</name>
<descriptions label="Slide" new="Image"/>
<tree>false</tree>
<table key="id_record" production="records" stage="records_stage" />
<order_by field="date_update" sort="DESC" />
<categories>true</categories>
<hierarchies>true</hierarchies>
<fieldset name="General informations" icon="page">
  <field id="id_record" column="true" kind="numeric">
   <type>hidden</type>
   <list>true</list>
   <admin>true</admin>
  </field>
  <field id="id_type" column="true" kind="numeric">
   <type>hidden</type>
   <list>true</list>
   <default>6</default>
  </field>
  <field id="date_insert" column="true" kind="numeric">
   <type>hidden</type>
   <list>true</list>
   <default>eval:time()</default>
  </field>
  <field id="published" column="true" kind="numeric">
   <type>hidden</type>
   <list>true</list>
   <default>0</default>
   <length>1</length>
  </field>
  <field id="title" column="true" link="edit">
   <description>Title</description>
   <type>text</type>
   <admin>true</admin>
   <list>true</list>
   <rules>required</rules>
  </field>
  <field id="date_publish" column="true">
   <description>Visibility date</description>
   <type>datetime</type>
   <admin>true</admin>
   <list>true</list>
  </field>
  <field id="uri" column="true">
   <description>Page URL</description>
   <type>text</type>
   <admin>true</admin>
   <list>true</list>
  </field>
  <field id="lang" column="true">
   <description>Language</description>
   <type>select</type>
   <admin>true</admin>
   <list>true</list>
   <options>
    <custom>config_item('website_languages_select')</custom>
   </options>
   <default>eval:$this->lang->default_language</default>
   <length>2</length>
  </field>
  <field id="teaser_image">
       <description>Gallery images</description>
       <type>images</type>
       <size>4096</size>
       <mimes>jpg|gif|png|jpeg</mimes>
       <encrypt_name>true</encrypt_name>
       <original>true</original>
       <resized>640x?</resized>
       <thumbnail>60x?</thumbnail>
       <max>3</max>
       <list>true</list>
  </field>
</fieldset>
</content>

#39
[eluser]kkzhi[/eluser]
still cant get the teaser_image property in the xml Sad

its always return a null value with debug($record->get('teaser_image')); but if i change into other field name it return a result

can somebody help?

#40
[eluser]areesto[/eluser]
hi kkzhi,

i think you need to add this line :
$record->set_documents(); before this one $record->get(‘teaser_image’);

hope it work



Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.