Note that there are some explanatory texts on larger screens.

plurals
  1. POregarding passed id to save data in the database using symfony framework
    primarykey
    data
    text
    <p>im new to symfony framework i make a jquery ajax form here it runs well it also saves the images to the uploads folder my problem here is it will not save to database the filename. how do i passed the id im not using the symfony form. Here is my code in indexSuccess.php</p> <pre><code> &lt;script&gt; $(document).ready(function(){ $("#loading").hide(); $('#send_form').ajaxForm({ target: '.result', beforeSubmit: validate, success: function(data) { $(".result").html(data); $(".result").show(); } }); }); function validate(){ var photoValue = $('input[name=files]').fieldValue(); if (!photoValue[0]){ alert('Please upload a picture of you.'); return false; } } &lt;/script&gt; &lt;div id="sf_admin_content"&gt; &lt;h2&gt;Company Gallery&lt;/h2&gt; &lt;br /&gt; &lt;form id="send_form" action="&lt;?php echo url_for('companyGallery/add'); ?&gt;" method="post"&gt; &lt;table id="tbl" class="company" cellspacing="0" style="width:500px;"&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="file" name="files" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" value="Upload" class="btn btn-success" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;br /&gt; &lt;div id="loading" &gt; &lt;img alt="loading" src="/images/preloader_transparent.gif" /&gt; &lt;/div&gt; &lt;div class="result"&gt; &lt;table id="tbl" class="company" cellspacing="0" style="width:250px;"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Photo&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php foreach($companyGallery as $x =&gt; $gallery): ?&gt; &lt;tr id="company&lt;?php echo $gallery-&gt;getId(); ?&gt;" class="&lt;?php echo ($x&amp;1) ? 'even':'odd'; ?&gt;"&gt; &lt;td align="right"&gt;&lt;?php echo $gallery-&gt;getId(); ?&gt;&lt;/td&gt; &lt;td&gt;&lt;a href="" target="_blank"&gt;&lt;img alt="" src="/uploads/companyGallery/&lt;?php echo $gallery-&gt;getImageFull(); ?&gt;" /&gt;&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach; ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>in the symfony code below</p> <pre><code>&lt;?php class addAction extends sfAction{ private function uploadPhoto($id,$file){ //echo "test"; if(!$id){ $dir = sfConfig::get('app_tempCompGallery_img_dir'); }else{ $dir = sfConfig::get('app_companyGallery_dir'); } $full = sfConfig::get('app_companyGallery_full'); $small = sfConfig::get('app_companyGallery_small'); $dir = sfConfig::get('app_companyGallery_dir'); $dir_150 = sfConfig::get('app_companyGallery_dir_150'); $file['ext'] = getFileExtension($file['name']); if(!$id){ $fileName = uniqid(). '.'.$file['ext']; }else{ $fileName = $id.'.'.$file['ext']; } $imagePath = $dir.$fileName; $image_full = encode('CompanyGallery-'.$id).'.'.$fileName; $image_small = encode('CompanyGallery-'.$id).'.'.$fileName; $image_full_path = $dir.$image_full; $image_small_path = $dir_150.$image_small; rename($file['tmp_name'],$image_full_path); $image = new myImageManipulator($image_full_path); $image-&gt;resample2($full, $full); $image-&gt;crop(0, 0, $full, $full); $image-&gt;save($image_full_path); $image = new myImageManipulator($image_full_path); $image-&gt;resample2($small, $small); $image-&gt;crop(0, 0, $small, $small); $image-&gt;save($image_small_path); //$companyGallery = $this-&gt;getUser()-&gt;getAttribute('companyGallery'); //$this-&gt;saveData($companyGallery); echo "test345"; $gallery = Doctrine_Core::getTable('CompanyGallery')-&gt;find($id); //var_dump($gallery);exit(); $gallery-&gt;setImageFull($image_full); $gallery-&gt;setImageSmall($image_small); $gallery-&gt;save(); } public function execute($request){ //echo "test macky 123"; //exit(); $gallery = new CompanyGallery(); print_r($gallery); $gallery_id = $gallery-&gt;getId(); echo "ASDFAS" .$gallery-&gt;getId(); exit(); $file = $this-&gt;request-&gt;getFiles(); print_r($file); $file = $file['files']; if($file &amp;&amp; $file['error'] == 0){ $this-&gt;uploadPhoto($gallery_id,$file); } } } </code></pre> <p>as youve notice in the <code>$gallery = Doctrine_Core::getTable('CompanyGallery')-&gt;find($id);</code> how do i pass the id in this code? please help..so that it will save to the database the filename</p> <p>heres my companyTable.class.php in lib/model folder</p> <pre><code>class CompanyGalleryTable extends Doctrine_Table { /** * Returns an instance of this class. * * @return object CompanyGalleryTable */ public static function getInstance() { return Doctrine_Core::getTable('CompanyGallery'); } public function getGalleryList($param=array()){ $q = Doctrine_Query::create() -&gt;from('CompanyGallery c') -&gt;orderBy('c.updated_at DESC'); $pager = new sfDoctrinePager('CompanyGallery',10); $pager-&gt;setQuery($q); $pager-&gt;setPage($param['curPage']); $pager-&gt;init(); return $pager; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload