Image ID not saving
Permalink
Hi everyone,
I have started to learn to create my own block and I wanted to allow a client to add an image to the block. I wanted to restrict the selection to only images as well.
So far I have watched Andrew's videos on Advanced Block Dev. In there he didn't explain how you would display a selected image within view.php. I have tried to find my around but failed. I wasn't able to find any reference to the Loader::helper() or asset_library within the 5.7. api
A lot of posts I found from Googling refered to 5.6 documentation.
Currently I created a new block called add_vehicle. This website will simply display vintages cars available for hire for proms, weddings and films.
The current result is I can choose an image from the library and it shows on the block. When I click save the image is dropped. It is not saved in fID and the view displays 0 as its value.
I have also added images to help show the problem
Scene setting;
db.xml:
form_setup_html.php code to note:
controller.php code to note:
view.php
I have started to learn to create my own block and I wanted to allow a client to add an image to the block. I wanted to restrict the selection to only images as well.
So far I have watched Andrew's videos on Advanced Block Dev. In there he didn't explain how you would display a selected image within view.php. I have tried to find my around but failed. I wasn't able to find any reference to the Loader::helper() or asset_library within the 5.7. api
A lot of posts I found from Googling refered to 5.6 documentation.
Currently I created a new block called add_vehicle. This website will simply display vintages cars available for hire for proms, weddings and films.
The current result is I can choose an image from the library and it shows on the block. When I click save the image is dropped. It is not saved in fID and the view displays 0 as its value.
I have also added images to help show the problem
Scene setting;
# concrete5 Version Core Version - 5.7.4.2 Version Installed - 5.7.4.2 Database Version - 20150504000000
db.xml:
<?xml version="1.0"?> <schema version="0.3"> <table name="btAddVehicle"> <field name="bID" type="I"> <key /> <unsigned /> </field> <descr>field stores image/file location</descr> <field name="fID" type="I"> <unsigned /> <default value="0" /> </field> <field name="title" type="C" size="100"> <NOTNULL /> </field>
Viewing 15 lines of 19 lines. View entire code block.
form_setup_html.php code to note:
<?php defined('C5_EXECUTE') or die("Access Denied."); $al = Loader::helper('concrete/asset_library'); //check image id if($fID >0) { $fo = image::getByID($fID); if ($fo->isError()) { unset($fo); } } ?> <!--Add image --> <fieldset> <legend><?php echo t('Image')?></legend> <div class="form-group">
Viewing 15 lines of 18 lines. View entire code block.
controller.php code to note:
<?php namespace Application\Block\AddVehicle; use Loader; use \Concrete\Core\Block\BlockController; class Controller extends BlockController { protected $btTable = 'btAddVehicle'; protected $btInterfaceWidth = "600"; protected $btWrapperClass = 'ccm-ui'; protected $btInterfaceHeight = "500"; protected $btCacheBlockRecord = true; protected $btCacheBlockOutput = true; protected $btCacheBlockOutputOnPost = true; protected $btCacheBlockOutputForRegisteredUsers = true; protected $btIgnorePageThemeGridFrameworkContainer = true;
Viewing 15 lines of 51 lines. View entire code block.
view.php
Thank you for the fast reply.
That makes sense why things are not working.
Sorry I am really new. I finished a HND in computing recently. I like web but I am fully aware my knowledge of coding is very limited.
I was asked to create this site. I tried on my course for my project to create a site using Drupal which I found impossible. I found Concrete a few weeks ago and so far so good. Its been a lot simpler to understand.
But I am at the moment just scrapping around. which isn't a good thing.
I think I just found a way to work with layout. I.E creating a 2 coll layout where I used the Content block and Image block. (one in each coll). This will work, but I feel its not simple enough for a client to use with no cms experiance.
But the gaps in my knowledge are making it much harder. I don't like to ask sometimes because my knowledge is so low.
Any way thanks again I shall take a look and see what sense I can make of it.
That makes sense why things are not working.
Sorry I am really new. I finished a HND in computing recently. I like web but I am fully aware my knowledge of coding is very limited.
I was asked to create this site. I tried on my course for my project to create a site using Drupal which I found impossible. I found Concrete a few weeks ago and so far so good. Its been a lot simpler to understand.
But I am at the moment just scrapping around. which isn't a good thing.
I think I just found a way to work with layout. I.E creating a 2 coll layout where I used the Content block and Image block. (one in each coll). This will work, but I feel its not simple enough for a client to use with no cms experiance.
But the gaps in my knowledge are making it much harder. I don't like to ask sometimes because my knowledge is so low.
Any way thanks again I shall take a look and see what sense I can make of it.
No need to be sorry, everyone starts out as a beginner. I am an amateur myself
Concrete5 5.7 has a lot of great things going for it. For someone new to development it has the added benefits of being written using modern PHP and general programming best practices. This makes it a very good learning tool. And the best way to learn it is to read all the documentation, get familiar with the API, and get your hands dirty exploring the install files, making things, and experimenting.
To best understand how everything works, you will need:
- a firm understanding of HTML and CSS
- basic knowledge of jQuery, JavaScript, and MySQL
- a solid grasp of PHP fundamentals
- at least a basic understanding of object-oriented PHP (OOP)
There are all sorts of resources online, but as a student you can get additional discounts on premium services (or potentially free through school or your local library). I recommend lynda.com and teamtreehouse.com, both offer high quality online training videos. See if you can get a free student or library member account for both and watch all the topics listed above (or where you feel you need help).
Concrete5 5.7 has a lot of great things going for it. For someone new to development it has the added benefits of being written using modern PHP and general programming best practices. This makes it a very good learning tool. And the best way to learn it is to read all the documentation, get familiar with the API, and get your hands dirty exploring the install files, making things, and experimenting.
To best understand how everything works, you will need:
- a firm understanding of HTML and CSS
- basic knowledge of jQuery, JavaScript, and MySQL
- a solid grasp of PHP fundamentals
- at least a basic understanding of object-oriented PHP (OOP)
There are all sorts of resources online, but as a student you can get additional discounts on premium services (or potentially free through school or your local library). I recommend lynda.com and teamtreehouse.com, both offer high quality online training videos. See if you can get a free student or library member account for both and watch all the topics listed above (or where you feel you need help).
Thanks for that, its very much appreciated!
I am no longer officially a student. :( as I have finished the HND now.
I decided not to sign up to complete a full degree. It seemed to me I didn't learn anything in detail and at the moment it really does seem I am unemployable. }
I figured it would be better to try and find some projects that I could use to learn and build up a portfolio as this seems rather important.
I was looking at the Nano degrees offered bu Udacity, but wasn't sure if they would be viable or recognized by employees.
I couldn't for a while work out if I wanted to do web or networking as I done equaly as well at each.
I was then asked just before my course finished if I could look at this website
http://www.apl-filmcars.co.uk and decided to help this person out.
so I am hoping I have made the right choice. I just worry that age is against me as I am starting at 29. (I spent a few years in the military as an infantry solider) I didn't get on with study before. But I am please I finished a HND. Now I just want make sure I am going in the right direction.
I am no longer officially a student. :( as I have finished the HND now.
I decided not to sign up to complete a full degree. It seemed to me I didn't learn anything in detail and at the moment it really does seem I am unemployable. }
I figured it would be better to try and find some projects that I could use to learn and build up a portfolio as this seems rather important.
I was looking at the Nano degrees offered bu Udacity, but wasn't sure if they would be viable or recognized by employees.
I couldn't for a while work out if I wanted to do web or networking as I done equaly as well at each.
I was then asked just before my course finished if I could look at this website
http://www.apl-filmcars.co.uk and decided to help this person out.
so I am hoping I have made the right choice. I just worry that age is against me as I am starting at 29. (I spent a few years in the military as an infantry solider) I didn't get on with study before. But I am please I finished a HND. Now I just want make sure I am going in the right direction.
Based on what you included in your first post, I built the block for you.
There is a view.css in the block folder for styling the block view.php output.
The block and screenshots have been attached to this reply.
There is a view.css in the block folder for styling the block view.php output.
The block and screenshots have been attached to this reply.
Oh wow!! That's unbelievable! Thank you! I will download and take a look at those files.
I believe the video you watched was for 5.6 block development.
Regarding Loader::helper(), helpers have been replaced by service providers. You can read more about it here - "Helpers Deprecated for Service Providers"https://www.concrete5.org/documentation/developers/5.7/background/mi... .
Some things that stand out at first glance:
- in your controller.php view() method, you don't need to set() those values, they should be available in view.php without extra steps
- also in controller.php, you don't need to override the save() method, save() automatically runs when you submit the edit form
- in view.php , you are echoing $fID - on its own it is just an integer (the file ID of the image, not the image object)
There are other things you need to display the image.
I think you will get great benefit from reading through the 5.7 documentation. Especially this section -https://www.concrete5.org/documentation/developers/5.7/working-with-... .
After you read that section, have a look at the core Testimonial block. It is a good basic block to copy and learn from - concrete\blocks\testimonial.