Simple Meteor + React + Iron Router CRUD application

- 1 answer

Ad

For the past 2 days, I've been struggling to create a Meteor + React + Iron Router project that offers the exact same functionality of this basic PHP + HTML page.

index.php

<?php
include('library.php');

// CREATE or UPDATE
if($_POST['save'] && $_POST['_id'])
    $db('tblProject')->update($_POST);
else if($_POST['save'])
    $db('tblProject')->insert($_POST);

// READ
$arrProject = $db('tblProject')->collection->find();
$arrCurrentProject = $db('tblProject')>collection->findOne(array('_id'=>$_GET['_id']));

$htmlForm = new DOMDocument();
$htmlForm->loadHTMLFile('form.html');
$input = $htmlForm->getElementsByTagName('input');
foreach ($input as $i) {
        $i->setAttribute('value',$arrCurrentProject[$i->getAttribute('name')]);
}
$textarea = $htmlForm->getElementsByTagName('textarea');
foreach ($textarea as $i) {
        $i->nodeValue = $arrCurrentProject[$i->getAttribute('name')];
}
?><!DOCTYPE html>
<html>
<head>
</head>
<body>
  <ul>
    <?php foreach($arrProject as $row) : ?>
        <li><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="<?php echo 'http://'.$_SERVER['SERVER_NAME'].'/project/'.$row['_id']; ?>">Project <?php echo $row['_id']; ?></a></li>
    <?php endforeach; ?>
  </ul>
  <?php echo $htmlForm->saveHTML(); ?>
</body>
</html>

form.html

  <form method="post">
     <span>Hello this is some text</span>
     <input type="text" name="input1"/>
     <p>Blah blah this is boring</p>
     <input type="text" name="input2"/>
     <img src="image-of-a-kangaroo.png" />
     <input type="text" name="input3" />
     <ul>
        <li>Buy brocolli</li>
        <li>Buy oregano</li>
     </ul>
     <input type="text" name="input4" />
     <textarea name="input100"></textarea>
     <input type="text" name="input101" />
     <p><strong>Yes, I like pizza!</strong><span>But my porcupine gets sick eating pizza.</span></p>
     <button type="submit" value="save">Save</button>
  </form>

In other words, I want to look up a database for a collection of projects and also display the current project if the url is /project/:_id. You can edit the form, or click on a link in the collection list to look at another form.

I've gone through the Meteor + React To Do list tutorial, but I'm still struggling with the basics. I still don't know how to re-build this simple PHP page as a meteor + react + iron router project. Can anyone show me an example or translate this for me?

An answer to this question will probably help me resolve a previous question I asked which is still outstanding: Meteor + React how to set the value of a lot of input elements and modify them after

Ad

Answer

Ad

I finally did it. The answer is the combination of the code presented in this question here:

Cannot update during an existing state transition

Then update the code with the accepted answer.

Ad
source: stackoverflow.com
Ad